Reputation: 4779
I'm trying to divide a number (12 in my case, due to using Foundation's Front End framework) by the number of pages that will appear in the typoscript-rendered menu of a page and output the result as part of a class name of the html menu items.
Currently, I can get typoscript to output the number of items in a menu with {register:count_menuItems}
, but I can't figure out how to divide this number and output the quotient.
Below is my code:
lib.navigation.secondary = HMENU
lib.navigation.secondary {
entryLevel = 1
stdWrap.dataWrap = <div class="row large-10 small-centered large-centered columns">|</div>
1 = TMENU
1 {
NO {
allWrap = <div class="large-{register:count_menuItems} small-12 columns first">|</div> |*| <div class="large-{register:count_menuItems} small-12 columns">|</div> |*| <div class="large-{register:count_menuItems} small-12 columns last">|</div>
allWrap.insertData = 1
stdWrap.cObject = COA
stdWrap.cObject {
# getting the navigation title with fallback to the title
10 = TEXT
10.field = nav_title // title
10.wrap = <h4>|</h4>
# getting the subtitle of the page
20 = TEXT
20.field = subtitle
20.wrap = <p>|</p>
}
}
}
}
Upvotes: 1
Views: 1026
Reputation: 4779
The following ended up working for me
NO {
before.cObject = LOAD_REGISTER
before.cObject {
menuItems.cObject = TEXT
menuItems.cObject {
current = 1
setCurrent.data = register:count_menuItems
setCurrent.wrap = 12/|
prioriCalc = 1
}
}
allWrap = <div class="large-{register:count_menuItems} small-12 columns first">|</div> |*| <div class="large-{register:count_menuItems} small-12 columns">|</div> |*| <div class="large-{register:count_menuItems} small-12 columns last">|</div>
allWrap.insertData = 1
...
Upvotes: 0
Reputation: 4558
I couldn't test it, but I think you can solve it by this approach:
First create a LOAD_REGISTER containing the result of the calculation:
page.5 = LOAD_REGISTER
# the default value
page.5.divClass = 12
page.5.divClass.cObject = TEXT
page.5.divClass.cObject {
value = 12
stdWrap.dataWrap = |/{register:count_menuItems}
prioriCalc = 1
}
Then use it in your navigation:
lib.navigation.secondary = HMENU
lib.navigation.secondary {
entryLevel = 1
stdWrap.dataWrap = <div class="row large-10 small-centered large-centered columns">|</div>
1 = TMENU
1 {
NO {
allWrap = <div class="large-{register:divClass} small-12 columns first">|</div> |*| <div class="large-{register:divClass} small-12 columns">|</div> |*| <div class="large-{register:divClass} small-12 columns last">|</div>
allWrap.insertData = 1
[...]
The tricky part could be the rendering order of the menu; I'm not sure if at the time you're creating your LOAD_REGISTER divClass the register count_menuItems is already available.
Upvotes: 0