I use Bootstrap_package v10 and Typo3 9, the menu processor doesn't show the level-3 and 4 for my pagetree.
I'm using the original templates from bootstrap package, the code is below:
10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
10 {
levels = 5
special = directory
special.value = 26969
expandAll = 1
includeSpacer = 1
as = mainnavigation
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = nav_icon
as = icon
if {
isTrue.stdWrap.cObject = COA
isTrue.stdWrap.cObject {
10 = TEXT
10.value = 1
10.if.isTrue = {$page.theme.navigation.icon.enable}
20 = TEXT
20.value = 1
20.if.isTrue = {$page.theme.navigation.dropdown.icon.enable}
}
}
}
}
}
and this is the fluid code :
<f:section name="MainNavigation">
<f:if condition="{menu}">
<ul class="navbar-nav">
<f:for each="{menu}" as="item">
<f:if condition="{item.spacer}">
<f:then>
</ul>
<ul class="navbar-nav">
</f:then>
<f:else>
<li class="nav-item{f:if(condition: item.active, then:' active')}{f:if(condition: item.children, then:' dropdown dropdown-hover')}">
<a href="{item.link}" id="nav-item-{item.data.uid}" class="nav-link{f:if(condition: item.children, then:' dropdown-toggle')}"{f:if(condition: item.target, then: ' target="{item.target}"')} title="{item.title}"{f:if(condition: item.children, then:' aria-haspopup="true" aria-expanded="false"')}>
<f:if condition="{theme.navigation.icon.enable} && {item.icon}">
<span class="nav-link-icon">
<f:if condition="{item.icon.0.extension} === svg">
<f:then>
<bk2k:inlineSvg image="{item.icon.0}" width="{theme.navigation.icon.width}" height="{theme.navigation.icon.height}" />
</f:then>
<f:else>
<f:image image="{item.icon.0}" alt="{item.icon.0.alternative}" title="{item.icon.0.title}" width="{theme.navigation.icon.width}" height="{theme.navigation.icon.height}" />
</f:else>
</f:if>
</span>
</f:if>
<span class="nav-link-text">{item.title}<f:if condition="{item.current}"> <span class="sr-only">(current)</span></f:if></span>
</a>
<f:if condition="{item.children}">
<ul class="dropdown-menu" aria-labelledby="nav-item-{item.data.uid}">
<f:for each="{item.children}" as="child">
<f:if condition="{child.spacer}">
<f:then>
<li class="dropdown-divider"></li>
</f:then>
<f:else>
<li>
<a href="{child.link}" class="dropdown-item{f:if(condition: child.active, then:' active')}"{f:if(condition: child.target, then: ' target="{child.target}"')} title="{child.title}">
<f:if condition="{theme.navigation.dropdown.icon.enable} && {child.icon}">
<span class="dropdown-icon">
<f:if condition="{child.icon.0.extension} === svg">
<f:then>
<bk2k:inlineSvg image="{child.icon.0}" width="{theme.navigation.dropdown.icon.width}" height="{theme.navigation.dropdown.icon.height}" />
</f:then>
<f:else>
<f:image image="{child.icon.0}" alt="{child.icon.0.alternative}" title="{child.icon.0.title}" width="{theme.navigation.dropdown.icon.width}" height="{theme.navigation.dropdown.icon.height}" />
</f:else>
</f:if>
</span>
</f:if>
<span class="dropdown-text">{child.title}<f:if condition="{child.current}"> <span class="sr-only">(current)</span></f:if></span>
</a>
</li>
</f:else>
</f:if>
</f:for>
</ul>
</f:if>
</li>
</f:else>
</f:if>
</f:for>
</ul>
</f:if>
</f:section>
The fluid is calling a page child but i don't know if it is recursive or not so it can showa all levels, what am I missing there, it seems like i'm the first one that having this issue ?
Thanks in advance for any help.
First you should verify if the data is available for more than the first two levels:
insert a <f:debug title="mainnavigation">{mainnavigation}</f:debug> in your template.
Then inspect your templates whether they are ready to display more than two levels.
I can imagine your templates show the first level, for second level a partial is called, but that partial does not call itself if necessary.
Except if you need some level specific markup (e.g. 'class="level1") you can build up menus by stacking the levels inside each other (giving stacked uls). So you either have a recursive call with stacked menus of the same markup or you define a partial for each level with individual markup (or you define a variable which contains the current level and call the partial recursive).
it's even worse: both levels are written out in the same template file, no partial (or section) is used.
I would change it to:
(I stayed with one file and instead of an additional partials I call a section, which can be in the same file)
<f:section name="MainNavigation">
<f:if condition="{menu}">
<ul class="navbar-nav">
<f:for each="{menu}" as="item">
<f:render section="subLevel" arguments="{item:item}" />
</f:for>
</ul>
</f:if>
</f:section>
<f:section name="subLevel">
<f:if condition="{item.spacer}">
<f:then>
<li class="dropdown-divider"></li>
</f:then>
<f:else>
<li class="nav-item{f:if(condition: item.active, then:' active')}{f:if(condition: item.children, then:' dropdown dropdown-hover')}">
<a href="{item.link}" id="nav-item-{item.data.uid}" class="nav-link{f:if(condition: item.children, then:' dropdown-toggle')}"{f:if(condition: item.target, then: ' target="{item.target}"')} title="{item.title}"{f:if(condition: item.children, then:' aria-haspopup="true" aria-expanded="false"')}>
<f:if condition="{theme.navigation.icon.enable} && {item.icon}">
<span class="nav-link-icon">
<f:if condition="{item.icon.0.extension} === svg">
<f:then>
<bk2k:inlineSvg image="{item.icon.0}" width="{theme.navigation.icon.width}" height="{theme.navigation.icon.height}" />
</f:then>
<f:else>
<f:image image="{item.icon.0}" alt="{item.icon.0.alternative}" title="{item.icon.0.title}" width="{theme.navigation.icon.width}" height="{theme.navigation.icon.height}" />
</f:else>
</f:if>
</span>
</f:if>
<span class="nav-link-text">{item.title}<f:if condition="{item.current}"> <span class="sr-only">(current)</span></f:if></span>
</a>
<f:if condition="{item.children}">
<ul class="dropdown-menu" aria-labelledby="nav-item-{item.data.uid}">
<f:for each="{item.children}" as="child">
<f:render section="subLevel" arguments="{item:child}" />
</for>
</ul>
</f:if>
</li>
</f:else>
</f:if>
</f:section>
Notice the changed markup for spacer in the first level!
Further changes might occur as I have not compared the code but concentrated on building up clean markup.
Increasing a 'parameter' for the recursion.
for an increasing value (level1, level2, level3...) you need a viewhelper in TYPO3 prior version 9:
this viewhelper can be realised in typoscript:
lib.math = TEXT
lib.math {
current = 1
prioriCalc = 1
}
then you can change the initial call to the SubLevel section to:
<f:render section="subLevel" arguments="{item:item,level:1}" />
Now you have a fluid variable level with the value 1.
the recursive call must be changed to:
<f:render section="subLevel" arguments="{item:child,level:{f:cObject(typoscriptObjectPath:'lib.math', data:'{level}+1')}}" />
for increasing values 2, 3, 4 ...
By default, MenuProcessor does not expand all levels. It will only show the branch you're on up to the level below the level you are on. If you want to show all levels for all branches you have to add expandAll = 1 to your configuration:
10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
10 {
levels = 5
expandAll = 1
...
}
Your Fluid template shows only 2 levels. By default in the Bootstrap package, you have a 2-level menu.
If you want to have more, you need to adjust the template to render more levels.
Here is the rendering of level 2 in your template:
<f:for each="{item.children}" as="child">
<f:render section="subLevel" arguments="{item:child}" />
</f:for>
If you want to render level 3, you need to go to the section subLevel and check if there are children of every item you set in arguments.
Example:
<f:if condition="{item.children}">
<ul>
<f:for each="{item.children}" as="level3Item">
...
</f:for>
</ul>
</f:if>
You should have some CSS for 5 levels of course. :)
I hope I could help you.
For levels beyond 2, I find it much easier to build in typoscript in your setup.typoscript.
lib.textmenu {
# We define the first level as text menu.
1 = TMENU
# The first level of this menu. 0 is rootline. -1 is 1 level up from rootline. 1 is 1 level down from rootline
entryLevel = 0
# UID's to exclude from the menu. Change this for each subsite, but will require a new template on each subsite.
excludeUidList = 21
# Turn spacers on, I use them to do sections of my menu.
1.SPC = 1
1.SPC.allWrap = <li class="a nav-item dropdown text-light bg-secondary SPC">|</li>
# Expand the whole menu - ie a sitemap
1.expAll = 1
# We define the normal state ("NO").
1.NO = 1
1.NO.wrap = <li class="nav-item NO">|</li>
1.NO.linkWrap = <li class="nav-item NO">|</li>
1.NO.ATagParams = class="nav-item dropdown NO"
# We define the active state ("ACT").
1.ACT = 1
1.ACT.wrapItemAndSub = <li class="nav-item active ACT">|</li>
# Get level 2 to get the format from level 1
2 <.1
# Do some customization for level 2
2.CUR = 1
2.CUR.wrapItemAndSub = <li class="nav-item dropdown active level2CUR">|</li>
2.CUR.ATagParams = class="active text-white"
# Make Levels 3 to 6 the same as level 1. I'll leave it to you to study all the typoscript wrapping.
3 < .1
4 < .1
5 < .1
6 < .1
}
Hello #Mohamed Masmoudi!
I am a newbie with TYPO3. I was asking myself the same question like you.
After a lot of research I found a solution which works for me (TYPO3 v10.4.12 and bootstrap-package) at least in desktop view mode.
But I don't understand what exactly is happening in mobile view. Maybe someone can give me a hint???
The sublevel is existing in source-code but is not showing up in mobile view.
First step was to modify the MenuProcessor in setup.typoscript
##########################
### DATA PREPROCESSING ###
##########################
dataProcessing {
1 = BK2K\BootstrapPackage\DataProcessing\ConstantsProcessor
1 {
as = theme
key = page.theme
}
10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
10 {
#modify these lines
levels = 5
expandAll = 1
includeSpacer = 1
as = mainnavigation
Second step modify the
/bootstrap_package/Resources/Private/Partials/Page/Navigation/Main.html
by adding the following lines to the fluid-template directly after the
<a href="{child.link}" class="dropdown-item{f:if(condition: child.active, then:' active')}"{f:if(condition: child.target, then: ' target="{child.target}"')} title="{child.title}">
...
</a>
here it comes:
<!-- 3rd Level -->
<ul class="dropdown-menu dropdown2-menu">
<f:for each="{child.children}" as="child2">
<li>
<a href="{child2.link}" class="dropdown-item{f:if(condition: child2.active, then:' active')}"{f:if(condition: child2.target, then: ' target="{child2.target}"')} title="{child2.title}">
<f:if condition="{theme.navigation.dropdown.icon.enable} && {child.icon}">
<span class="dropdown-icon">
<f:if condition="{child.icon.0.extension} === svg">
<f:then>
<bk2k:inlineSvg image="{child.icon.0}" width="{theme.navigation.dropdown.icon.width}" height="{theme.navigation.dropdown.icon.height}" />
</f:then>
<f:else>
<f:image additionalAttributes="{loading: 'lazy'}" image="{child.icon.0}" alt="{child.icon.0.alternative}" title="{child.icon.0.title}" width="{theme.navigation.dropdown.icon.width}" height="{theme.navigation.dropdown.icon.height}" />
</f:else>
</f:if>
</span>
</f:if>
<span class="dropdown2-text">{child2.title}<f:if condition="{child2.current}"> <span class="sr-only">(current)</span></f:if></span>
</a>
</li>
</f:for>
</ul>
<!-- End of 3rd Level -->
As you see I added a child2. You can add further sublevels like child3 etc by adding them after the particular <a>...</a>-tag
Don't forget to close all the open tags.
To separate the new sublevels by CSS I added a dropdown2-menu-Class to the tag.
Now you can add for example a .dropdown2-menu {margin-left: 50px} to your CSS.
Of course it is better not to touch the Bootstrap-Package. Instead use your own sitepackage. You can build one # https://sitepackagebuilder.com/
All of this is only to remember myself, what I was doing and maybe to help others... :-)
I have a TYPO3 9.5.0LTS and use the bootstrap package theme. It seems to be all working ... except ... when I add a link (internal or external) to a carousel item ... nothing gets rendered. The other elements come out fine.
I looked in the CalltoAction.html ... and found out that pageUid of f:link.page is not reading t3://page?uid=80.
When I {records} ... I get link => 't3://page?uid=80' (16 chars)
And when I test in CalltoAction.html:
<p>{item.data.link}</p>
<f:if condition="{item.data.link}">
<f:link.page pageUid="1" class="carousel-item-button btn btn-primary" additionalAttributes="{draggable:'false'}">
<f:if condition="{item.data.button_text}">
<f:then>
<span>{item.data.button_text}</span>
</f:then>
<f:else>
<span><f:translate key="readmore" extensionName="bootstrap_package" /></span>
</f:else>
</f:if>
</f:link.page>
</f:if>
<f:if condition="{item.data.link}">
<f:link.page pageUid="{item.data.link}" class="carousel-item-button btn btn-primary" additionalAttributes="{draggable:'false'}">
<f:if condition="{item.data.button_text}">
<f:then>
<span>{item.data.button_text}</span>
</f:then>
<f:else>
<span><f:translate key="readmore" extensionName="bootstrap_package" /></span>
</f:else>
</f:if>
</f:link.page>
</f:if>
I get the following result in the FE:
<p>t3://page?uid=80</p>
<a draggable="false" class="carousel-item-button btn btn-primary" href="/"><span>Read more</span></a>
<span>Read more</span>
So pageUid of f:link.page not reading t3://page?uid=80
How can I solve this?
the f:link.page-VH expects an integer (uid) in the parameter pageUid.
t3://page?uid=80 by way is no integer but a string. A special string which can be handled by the f:link.typo3link-VH
i have a simple extbase extension with a model "item".
Each item has a title, a description and a date.
How can i list my items according to the date?
e.G.
24.06.17:
item 2
item 6
item 7
25.06.14:
item 1
...
i search the logic to realize this (in the view or in the controller)
In your code you can sort your record by date.
In fluid you can use the vhs viewhelpers set:
https://fluidtypo3.org/viewhelpers/vhs/master/Variable/SetViewHelper.html
Something likes (I don't test it):
<f:for each="items" as="item">
<f:if condition="{item.date}=={current}">
<f:then>
{item.title}
</f:then>
<f:else>
<br/>{item.date}: {item.title}
</f:else>
</f:if>
<v:variable.set name="current" value="{item.date}" />
</f:for>
You can use vhs viewhelpers like below.
<f:for each="{dataset -> vhs:iterator.sort(sortBy: 'date')}" as="item">
.........
.........
</f:for>
I try to build a Mask CE element, an accordion.
As you can see here: http://www.pizzaworkshop.nl/index.php?id=3 it is partly working. Though I need some help to get this right (by lack of some good samples on the net).
this is what I have as fluid template (I,m using foundation6 :)
So all parts seems to be there but how to get the "repetition' in the html?
<f:if condition="{data.tx_mask_planned_header}">
<f:format.nl2br>{data.tx_mask_planned_header}</f:format.nl2br>
</f:if>
<ul class="accordion" data-accordion>
<li class="accordion-item" data-accordion-item>
<a href="#" class="accordion-title"><f:if condition="{data.tx_mask_workshop_gepland}">
<f:for each="{data.tx_mask_workshop_gepland}" as="data_item">
<f:if condition="{data_item.tx_mask_datum_workshop}">
<f:format.date format="d.m.Y">{data_item.tx_mask_datum_workshop}</f:format.date>
</f:if>
<f:switch expression="{data_item.tx_mask_soort_workshop}">
<f:case value="1">Pizza -Fun Workshop</f:case>
<f:case value="2">Pizza - Master Workshop</f:case>
<f:case value="3">Pizza - Midsummer Pizza</f:case>
</f:switch>
</a>
<div class="accordion-content" data-tab-content>
<h4>
<f:if condition="{data_item.tx_mask_workshop_state}">
<f:switch expression="{data_item.tx_mask_workshop_state}">
<f:case value="1"><b>Nieuwe workshop!<b/></f:case>
<f:case value="2">Deze workshop is vol!</f:case>
<f:case value="3">Nog enkele plaatsen beschikbaar</f:case>
</f:switch>
</f:if>
</h4>
<div class="callout">
<f:if condition="{data_item.tx_mask_workshop_info}">
<f:format.html parseFuncTSPath="lib.parseFunc_RTE">{data_item.tx_mask_workshop_info}</f:format.html>
</f:if>
<button class="button-red"> <f:if condition="{data_item.tx_mask_workshop_form_link}">
<f:link.page pageUid="{data_item.tx_mask_workshop_form_link}"></f:link.page>
</f:if>
</button>
</div>
</div>
</li>
</f:for>
</ul>
</f:if>
I have an accordion, where the accordion-content are own CEs. So my rendering consists of:
<ul class="accordion" data-accordion>
<f:for each="{data.tx_mask_accordionitems}" as="accordion_item">
<f:cObject typoscriptObjectPath="lib.tx_mask.content">{accordion_item.uid}</f:cObject>
</f:for>
</ul>
our mask definitions ...
... for Slider (only slider_elements allowed):
... the slider element:
... tabs (multiple CEs as subelements allowed):
your solution might differ if your CE definition might vary. please add the mask definition of your CE.
I define an array in my extensions setup.txt typoscript like so:
settings{
halls {
0 = Default
1 = Mississauga
2 = Halifax
3 = Niagara Falls
4 = Oakville
5 = Pickering
}}
how in my fluid template can I find the length of the halls array? I want an if condition to do one thing if length is greater than 1 and another if not.
I am using typo3 v4.5.32 with extbase 1.3.
Thank you.
I tried this but it puts out two <th> tags instead of just one. The first if is meant to prove that there is more than one element, the next is meant to print out a <th> only if it is the first element.
<f:for each="{settings.halls}" as="hall" key="number" iteration="itemIteration">
<f:if condition="{itemIteration.isFirst != itemIteration.isLast}">
<f:if condition="{itemIteration.index == 0}">
<th>
<f:translate key="tx_bpscoupons_domain_model_coupon.hall" />
</th>
</f:if>
</f:if>
</f:for>
Why?
UPDATE: here is my work around for a lack of "is array length > 1" ferature in fluid
<f:for each="{settings.halls}" as="hall" key="number" iteration="itemIteration">
<f:if condition="{itemIteration.isFirst}">
<f:then>
<f:if condition="{itemIteration.isLast}">
// if both first and last there is only one so skip
</f:if>
</f:then>
<f:else>
<f:if condition="{itemIteration.isLast}">
//if there is more than one element in halls then eventually you'll get here once so print out th tags
<th>
<f:translate key="tx_bpscoupons_domain_model_coupon.hall" />
</th>
</f:if>
</f:else>
</f:if>
</f:for>
and to print out data:
<f:for each="{settings.halls}" as="hall" key="number" iteration="itemIteration">
<f:if condition="{itemIteration.isFirst}">
<f:then>
<f:if condition="{itemIteration.isLast}">
<f:then>
</f:then>
<f:else>
<f:if condition="{number} == {coupon.hall}">
<td>{hall}</td>
</f:if>
</f:else>
</f:if>
</f:then>
<f:else>
<f:if condition="{number} == {coupon.hall}">
<td>{hall}</td>
</f:if>
</f:else>
</f:if>
</f:for>
ugly but seems to work.
UPDATE 2 :
DOH!!! I missed total, just what I needed but I was looking for length or count, so this code is what I want:
<f:for each="{settings.halls}" as="hall" key="number" iteration="itemIteration">
<f:if condition="{itemIteration.total} > 1">
<f:if condition="{itemIteration.isLast}">
<th><f:translate key="tx_bpscoupons_domain_model_coupon.hall" /></th>
</f:if>
</f:if>
</f:for>
You can find a length of an array with the f:count ViewHelper. Just like other ViewHelper it can be used as an inline notation (You can find more here)
The correct code would be:
<f:if condition="{settings.halls -> f.count()} > 1">
<f:then>
//your code for then
</f:then>
<f:else>
//your code for else
</f:else>
</f:if>
<f:if condition="{f:count(subject: settings.halls)} > 1"> do something </f:if>
see update#2 above for the answer. to reiterate:
<f:for each="{settings.halls}" as="hall" key="number" iteration="itemIteration">
<f:if condition="{itemIteration.total} > 1">
<f:if condition="{itemIteration.isLast}">
<th><f:translate key="tx_bpscoupons_domain_model_coupon.hall" /></th>
</f:if>
</f:if>
</f:for>
For those of you who are looking for a custom viewhelper for this:
class ArrayCountViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* Get array count
*
* #param mixed $array
* #return string
*/
public function render($array) {
if (!is_array($array))
return 0;
return count($array);
}
}