"isChildPage" is not found, despite "hasSubPages" is - typo3

So I need to use the "isChildPage" viewhelper in fluid. However it does not work, and if I run
<f:debug>{item}</f:debug>
For the item/page in question I get nothing for childpage. Its sibling viewhelper "hasSubPage" however works fine, and both classes are located in the same Page folder in the vhs extension.
So I am at a loss.
My use of the code:
<v:menu pageUid="{parent}" entryLevel="2" class="sidebar-nav" includeSpacers="1">
<f:for each="{menu}" as="item">
<a href="{item.link}" class=" {f:if(condition: item.isChildPage, then: 'hidden', else:'nope')}">

There isn't an attribute for 'item' called 'isChildPage' in newer vhs versions (https://fluidtypo3.org/viewhelpers/vhs/master/)
Which output do you want to receive?
Use
{f:if(condition: item.pid > 0, then: 'hidden', else:'nope')}
or
{f:if(condition: item.pid == 0, then: 'nope', else:'hidden')}
item.pid is the UID of the parent page.
This will set class 'hidden' to all links except root page link.

Related

TYPO3 tx_news: category-specific CSS styling

I´m using a Typo3 V9 together with the tx_news extension by G. Ringer. The extension is working very well, there´s only one feature I didn´t found:
Having different news categories, I want to style the teasertext in list view different for each category.
So I need a CSS class varying for every category (best would be the UIDs of the category records mapped directly into a css class). How can I accomplish this?
get inspired by the partial for the categories (ext:news/Resources/Private/Partials/Category/Items.html):
<f:section name="category-classes">
<f:for each="{categories}" as="category"> cat-class-{category.uid}</f:for>
</f:section>
and build it into your template (list, detail, ...)
e.g. the list item (ext:news/Resources/Private/Partials/List/Items.html) modify line 8 from
<div class="article articletype-{newsItem.type}{f:if(condition: newsItem.istopnews, then: ' topnews')}" itemscope="itemscope" itemtype="http://schema.org/Article">
to
<div class="article articletype-{newsItem.type}{f:if(condition: newsItem.istopnews, then: ' topnews')}{f:render(section:'category-classes', arguments:'categories:newsItem.categories')}" itemscope="itemscope" itemtype="http://schema.org/Article">

Check if linked page with typolink is hidden or not

<f:link.typolink parameter="{mylink"> links to a internal page- when this page is hidden / not visible in backend no is set.
This breaks my html:
Instead of
<div class="mylink">
my text
</div>
I get
<div class="mylink">my text/div>
Is there a way to check if the linked page is visible / not hidden?
You can use the f:uri.typolink viewhelper to check if the resulting URI is empty or not and then generate the link with f:typolink as normal:
<f:if condition="{f:uri.typolink(parameter: mylink)}">
<f:link.typolink parameter="{mylink}">my text</f:link.typolink>
</f:if>
If you do not care about attributes set in {mylink}, e.g. class or target you can reuse the already generated URI:
<f:alias map="{uri: '{f:uri.typolink(parameter: mylink)}'}">
<f:if condition="{uri}">
my text
</f:if>
</f:alias>

TYPO3 fluid_styled_content - Menu when using gridelements

how can i build a TYPO3 special-Menu in fluid with tt_content Header Elements, not the "pages" ?
https://docs.typo3.org/typo3cms/extensions/fluid_styled_content/7.6/ContentElements/Menu/Index.html
The Type-3 is a good Example, but i can only selected in the BE the Pages, not the tt_content - Elements.
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:ce="http://typo3.org/ns/TYPO3/CMS/FluidStyledContent/ViewHelpers" data-namespace-typo3-fluid="true">
<ce:menu.list pageUids="{pageUids}" as="pages">
<f:if condition="{pages}">
<ul class="ce-menu ce-menu-3">
<f:for each="{pages}" as="page">
<ce:menu.section pageUid="{page.uid}" as="contentElements" type="header">
<f:if condition="{contentElements}">
<f:for each="{contentElements}" as="contentElement">
<li>
<f:link.page pageUid="{page.uid}" section="c{contentElement.uid}">
{contentElement.header}
</f:link.page>
</li>
</f:for>
</f:if>
</ce:menu.section>
</f:for>
</ul>
</f:if>
</ce:menu.list>
</html>
I suppose you get back content elements which have "Show in Section Menus" enabled, and have the header filled and not hidden. The menu.section viewhelper does not have the possibility to filter on content element type. The type="header" argument of the view helper is not a filter for the content element type, but checks if there is a visible header_layout and the header field is not empty. I agree, the argument name type is misleading.
If you want to filter on content type (CType), add an extra "if" statement, filtering on {contentElement.CType} == header during the iteration of the content elements
<f:for each="{contentElements}" as="contentElement">
<f:if condition="{contentElement.CType} == 'header'">
<li>
<f:link.page pageUid="{page.uid}" section="c{contentElement.uid}">
{contentElement.header}
</f:link.page>
</li>
</f:if>
</f:for>
Better would be to write your own view helper for this, if you have the knowledge to do it.
First of all you should rename your question so it is clear that you want to create a content menu that works with grid_elements
I had the same problem and could not find another way but to create a small extension for that purpose since you have to modify the search query for the content. You can find it here: https://typo3.org/extensions/repository/view/gridelements_content_menu
There is currently no manual, just install the extension and include the static TS in your template. The resulting Menu might not be sorted right if your content elements are nested deeper than one level with grid_elements

Extbase FAL file download

I have question about file download with Extbase and FAL.
I can render image with
<f:image src="{file.uid}" alt="" width='100' height="100" treatIdAsReference="1"/>
I can get image, but I also have PDF file for download, and I can't use this ViewHelper.
Is there any other ViewHelper for file downloads?
If i dump that file i get this:
file => TYPO3\CMS\Extbase\Domain\Model\FileReferenceprototypepersistent entity (uid=1342, pid=310)
originalResource => NULL
uid => 1342 (integer)
_localizedUid => 1342 (integer)modified
_languageUid => 0 (integer)modified
pid => 310 (integer)
originalResource is null for file, and for image, image is printed with that ViewHelper. And I can't get file...
Any help is welcome...
You can use the publicURL property of the originalResource to create a file link.
Sample Fluid to generate a list of files referenced in your domain model property
<ul class="download-list">
<f:for each="{myObject.myFALproperty}" as="file" >
<li>{file.originalResource.title}</li>
</f:for>
</ul>
Just use the {myObject.myFALproperty} to see what you can access.
If you need more properties here are the basics of the Original and the reference in case you want to use the override located in the FlexForm
Original Attributes
filename :{myObject.myFALproperty.originalResource.originalFile.name}
title:{myObject.myFALproperty.originalResource.originalFile.title}
description:{myObject.myFALproperty.originalResource.originalFile.description}
alt:{myObject.myFALproperty.originalResource.originalFile.alternative}
uid:{myObject.myFALproperty.originalResource.originalFile.uid}
path:{myObject.myFALproperty.originalResource.publicUrl}
Reference Attributes
title: {myObject.myFALproperty.originalResource.title}
description {myObject.myFALproperty.originalResource.description}
Hope that helps.
Just for reference this is what the according TCA looks like, but you obviously already know that (note this sample has a maxitems setting of 10:
'myFALproperty' => array(
'exclude' => 0,
'label' => 'LLL:EXT:xy_sample/Resources/Private/Language/locallang_db.xlf:tx_xysample_domain_model_myobject.myFALproperty',
'config' =>
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'myFALproperty',
array('maxitems' => 10)
),
),
Step 1/2
You can get the URI to the PDF file like this:
In your FLUID Template:
<f:uri.image src="{file.uid}" treatIdAsReference="1"/>
OUTPUT
/path/to/your/pdf
This works even if "originalResource is null for file", like you stated in your question.
Step 2/2
Create a link in your FLUID Template (using inline notation)
<a href="{f:uri.image(src:'{file.uid}', treatIdAsReference: 1)}">
Download PDF
</a>
Test environment
typo3 v7.6.19
You can use the VHS viewhelper for that.
Check it out the following code:
<v:resource.file additionalAttributes="{foo: 'bar'}" data="{foo: 'bar'}" identifier="[mixed]" categories="[mixed]" treatIdAsUid="1" treatIdAsReference="1" as="NULL">
<!-- tag content - may be ignored! -->
</v:resource.file>
Link to the documentation:
https://fluidtypo3.org/viewhelpers/vhs/master/Resource/FileViewHelper.html
You have to install the vhs extension and also to add the namespace on your template file.
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
As a last thing you should have the files indexed in typo3. For that create a scheduler task and select the File Abstraction Layer: Extract metadata in storage task.

FLUID ViewHelper form in new window

I would like to add the target attribute to a FLUID form, so that after submitting the form, a new window is created.
This does not work, and produces an error:
<f:form target="_blank" action="..." name="..." id="..." pageUid="..." controller="..."></f:form>
Any ideas on how to make the to open in a new window?
I use TYPO3 6.2beta5
As the f:form ViewHelper inherits from the AbstractTagBasedViewHelper, it shares the same allowed attributes.
The fluid documentation inside the TYPO3 Flow documentation shows you all allowed attributes.
To answer your question, the correct way to use it would be:
<f:form additionalAttributes="{target:'_blank'}">FORMCONTENT</f:form>
Note that the additionalAttributes argument is an array. If you were to add more than 1 custom attribute, you would do it like that:
<f:form additionalAttributes="{target:'_blank', data-validate: 'foo'}">FORMCONTENT</f:form>
EDIT
The AbstractTagBasedViewHelper changed, so the answer as of today for TYPO3 CMS v7 would be: There's an attribute data for that which takes an array of keys and values.
<f:form data="{foo: 'bar', validate: 'baz'}" ....>
FORMCONTENT
</f:form>