TYPO3 - get last element of a splitted string - typo3

Trying to get the last part of the url as a body class. So far I got the slug of the page and split it by /
page.bodyTag >
page.bodyTagCObject = TEXT
page.bodyTagCObject.field = slug
page.bodyTagCObject.split {
token = /
cObjNum = 1
1.10 = TEXT
1.10.current = 1
1.10.noTrimWrap = | ||
1.10.dataWrap = |
1.10.required = 1
}
With this code, I am getting:
url: page/foo/bar/
class="page foo bar"
I need to get class="bar"

You'll need to use optionSplit for that. For example:
lib.test = TEXT
lib.test {
value = 1,2,3,4
split {
token = ,
cObjNum = 1 |*| 2 |*| 3
1 = TEXT
1 {
current = 1
wrap = First item:|<br/>
}
2 = TEXT
2 {
current = 1
wrap = Middle item:|<br/>
}
3 = TEXT
3 {
current = 1
wrap = Last item:|<br/>
}
}
}
1 |*| 2 |*| 3 means: use 1 for the first item, 3 for the last item and 2 for the rest.
You can just not set the ones you don't want, so this will only show the last item:
cObjNum = 1 |*| 1 |*| 2
2 = TEXT
2 {
current = 1
wrap = Last item:|<br/>
}

Related

TYPO3 split different wrap for first line using optionSplit

I am getting the text from the abstract field and splitting it by new line.
What I want is to wrap the first line in an H5 tag and all lines after in P tags.
This is what I have tried:
tt_content.menu.20.102 = HMENU
tt_content.menu.20.102 {
1 = TMENU
1 {
NO = 1
NO {
doNotLinkIt = 1
stdWrap.cObject = COA
stdWrap.cObject {
50 = TEXT
50.stdWrap {
field = abstract
split {
token.char = 10
cObjNum = 1 || 2
1.current = 1
1.wrap = <h5>|</h5>
2.current = 1
2.wrap = <p>|</p>
}
}
}
}
}
}
But it wraps all the lines in H5... How do I make this work?
I found a bug report that mentions this issue here: https://forge.typo3.org/issues/59533
It seems the best workaround that I can see is to instead use listNum
This has the obvious drawback of only working with a limited number of paragraphs but at least it sort of works.
10 = TEXT
10.field = abstract
10.wrap = <h5>|</h5>
10.listNum = 0
10.listNum.splitChar = 10
20 < .10
20.wrap = <p>|</p>
20.listNum = 1
30 < .20
30.listNum = 2
Just a combination of both, the original code and the listNum workaround should do the job. Still have to find a way to get the rest of the first "split" into the second one. So consider this answer to be WIP please. We are still discussing it on our Coders.Care Twitch channel in the TYPO3 service station.
10 = TEXT
10.field = abstract
10.wrap = <h5>|</h5>
10.listNum = 0
10.listNum.splitChar = 10
20 < .10
20.listNum = 1
20.split {
token.char = 10
cObjNum = 1
1.current = 1
1.wrap = <p>|</p>
}

Get list of feusers with typoscript, can't get the names of the associated usergroups

I am generating this list of feusers and trying to get the names of the associated usergroups. This code worked before the update to TYPO3 8.x (it's just the relevant part of the whole thing):
40 = TEXT
40.field = usergroup
40.split {
token = ,
cObjNum = 1 || 2
1 {
10 = CONTENT
10.table = fe_groups
10.select.pidInList = 22
10.select.andWhere.current = 1
10.select.andWhere.wrap = uid=|
10.select.where = (title NOT LIKE 'Netzwerk')
10.renderObj = TEXT
10.renderObj.field = title
10.renderObj.wrap = |, <br />
}
2 < .1
2.10.renderObj.wrap >
}
With TYPO3 8 the 'andWhere' is depreciated and so I tried like this, but failed:
40 = TEXT
40.field = usergroup
40.split {
token = ,
cObjNum = 1 || 2
1{
10 = CONTENT
10 {
table = fe_groups
select {
pidInList = 22
where.current = 1
where.wrap = uid= |
}
10.renderObj = TEXT
10.renderObj.field = title
10.renderObj.wrap = |,
}
2 < .1
2.10.renderObj.wrap
}
}
Thanks for pointing me in the right direction.
You should not split up the comma separated values, but go for uidInList instead. This way you get rid of the surrounding split and fetch the elements within just one go.
40 = CONTENT
40 {
table = fe_groups
select {
uidInList.field = usergroup
pidInList = 22
}
renderObj = TEXT
renderObj.field = title
renderObj.wrap = |,
}

Typo3 Breadcrumb with stdWrap.data possible?

I am new to Typo3 and wanted to have something like this: date / page1 > page2 > page3...
I know how to make a simple breadcrumb but now I wonder how I can put the current date in front of it. When I try the stdWrap.data + stdWrap.dataWrap the breadcrumb doesn't show.
20 = HMENU
20 {
special = rootline
special.range = 0 | -1
stdWrap.data = date : d.m.Y :::
stdWrap.dataWrap = <p> | </p>
//wrap = <p> | </p>
1 = TMENU
1 {
NO = 1
NO.allWrap = | >
CUR = 1
CUR.allWrap = |
}
}
Currently I don't know if I had to write to objects in typoscript for it or if I could do it in once like I tried. Maybe you can hint me to something or explain a simple way. Thanks!
You need to do a proper wrapping.
20.stdWrap.data
is no wrap at all and will be ignored so you might only get an empty p-tag from the stdWrap.dataWrap.
Following your attempt I think you want something like:
20.dataWrap = <p>{date:d.m.Y}</p> |
so I don't get it why you use a p tag to get all in one line.
I would propose a different TypoScript:
lib.breadcrumb = COA
lib.breadcrumb {
stdWrap.wrap = <ul>|</ul>
10 = TEXT
10 {
wrap = <li>|</li>
data = date : U
strftime = %A, %e. %B %Y
}
20 = HMENU
20 ... your TS for the breadcrumb menu
}

Typoscript - Simplifying passing parameters to an object

I have the following object in Typoscript, that I want to reuse several times:
module.headedmenu = COA
module.headedmenu{
10 = HMENU
10{
wrap = <nav><ul><li>|</li></ul></nav>
special = list
special.value = ###ROOTID###
1 = TMENU
1.NO.doNotLinkIt = 1
}
20 = HMENU
20{
wrap = <nav><ul>|</ul></nav>
special = directory
special.value = ###ROOTID###
1 = TMENU
1{
#Do we really need this??
expAll= 1
NO = 1
NO.wrapItemAndSub = <li class="first-level">|</li>
ACT = 1
ACT.wrapItemAndSub = <li class="first-level active">|</li>
}
}
}
This can be reused like this:
10 < module.headedmenu
10.10.special.value = 3
10.20.special.value = 3
20 < module.headedmenu
20.10.special.value = 12
20.20.special.value = 12
Is there a way to refactor this, so that I do not need to input more than once the root id? Constants dont cut it, because I want to use it several times. I do not want to have a huge constant list. I want to use it, more like a function that can be passed paramenters.
Is this doable?
You can use registers:
# Query register where the root id is needed:
module.headedmenu {
[...]
special.value = {register:rootId}
special.value.insertData = 1
[...]
}
# Set register before rendering element, and
# restore it afterwards:
10 = COA
10 {
10 = LOAD_REGISTER
10 {
rootId = 3
}
20 < module.headedmenu
30 = RESTORE_REGISTER
}

tt_news in Menu

In need to create a special and complicated menu. It should display in the Level 2 all sub-page with the latest news of their parent page (level 1) (I used tt_news and I created news for each page level 1). Here is my source code, it is composed of two parts, it shows in all level2 menu juste only the news of the first parent page(level 1).
The first part:
lib.var1 < plugin.tt_news
lib.var1 {
code >
code = LATEST
templateFile= fileadmin/news_template.tmpl
categoryMode = 0
pid_list >
pid_list.insertData = 1
pid_list = {data:pid}
catImageMode = 1
catTextMode = 0
latestLimit = 1
}
The second part:
lib.field_menu= HMENU
lib.field_menu {
entryLevel = 0
### first level ###
1 = TMENU
1 {
noBlur = 1
expAll = 1
wrap = |
NO = 1
NO {
allWrap = |
ATagTitle.field = title
}
}
### secondary Level ###
2 = TMENU
2 {
noBlur = 1
stdWrap.wrap = <ul style=""><li> | </li></ul>
stdWrap.innerWrap = <div><ul>|</ul></div>
stdWrap.innerWrap2.preCObject =< lib.var1
NO = 1
NO {
linkWrap= <li class="">|</li>
ATagTitle.field = title
}
}
}
}
Try:
pid_list >
pid_list = TEXT
pid_list.insertData = 1
pid_list.data = field : pid
instead if {data:pid}.