Typoscript modify a field:variable - typo3

I have this typoscript:
tt_content.gridelements_pi1.20.10.setup {
3cols.outerWrap = <div>|</div>
3cols.outerWrap.override.insertData = 1
3cols.outerWrap.override = <div id="{field:tx_cewrap_id_input}" class="{field:tx_cewrap_class_input} {field:tx_cewrap_class_select}">|</div>
3cols.outerWrap.override.if.isTrue.field = tx_cewrap_active
}
Which makes sure a wrapper is made around a certain element. The following html is generated as an example:
<div id="" class="full-box full-box-features container pt-75,pb-75"></div>
As you can see there is a comma separated string inserted as "tx_cewrap_class_select". With the {field:tx_cewrap_class_select} part:
pt-75,pb-75
But i want the comma to be a space character so the classes work in html
Now I know about the split option
But how do I fix the code, just need somehow to remove the comma! That's it :)
Thanks in advance for any response I can use.

You can split by comma and join with a space, but in this case it might be easier just to replace the comma by space:
10 = TEXT
10.replacement {
1 {
search = ,
replace.char = 32
}
}
And here the solution with split. it should be obvious why not to use:
10 = TEXT
10.split {
token = ,
cObjNum = 1 || 2
1.current = 1
2.current = 1
2.noTrimWrap = | ||
}
Hint:
on TEXT you can use stdWrap functions immediately,
in other context you might need an explicit .stdWrap:
10.stdWrap.replacement {
10.stdWrap.split {
Either you prepare your values into a register for later use, or you split your override value into a COA. You even might use the replacement on the whole override value in case you are sure no other comma might be needed.
COA-Solution:
(don't forget the noTrimWrap for 20 otherwise the classes are appended without space)
override.cObject = COA
override.cObject {
10 = TEXT
10.value <div id="{field:tx_cewrap_id_input}" class="{field:tx_cewrap_class_input}
10.insertData = 1
20 = TEXT
20.field = tx_cewrap_class_select
20.replacement {
1 {
search = ,
replace.char = 32
}
noTrimWrap= | ||
}
30 = TEXT
30.value = ">|</div>
}

Related

TYPO3 typoscript if condition based on site language

My typo3 version is 11.5.10.
I have two footer images, one for German and one for English .
I want to render different image for different language.
I tried this way for German language.
[siteLanguage("locale") == "de_DE"]
50 = COA
50 {
wrap = <div class="footer__item col-sm-6 col-md-3 img-custom">|</div>
stdWrap {
typolink {
parameter = {$myconstant.footer-logo-link-4}
parameter.noTrimWrap = || _blank|
}
}
50 = IMAGE
50 {
file = user_uploads/german-footer.png
layoutKey = srcset
layout.srcset {
element = <img WIDTH###" SOURCECOLLECTION###" ###PARAMS### ###ALTPARAMS### ###SELFCLOSINGTAGSLASH###> }
}
}
[end]
And for English language.
[siteLanguage("locale") == "en_US"]
50 = COA
50 {
wrap = <div class="footer__item col-sm-6 col-md-3 img-custom">|</div>
stdWrap {
typolink {
parameter = {$myconstant.footer-logo-link-5}
parameter.noTrimWrap = || _blank|
}
}
50 = IMAGE
50 {
file = user_uploads/english-footer.png
layoutKey = srcset
layout.srcset {
element = <img WIDTH###" SOURCECOLLECTION###" ###PARAMS### ###ALTPARAMS### ###SELFCLOSINGTAGSLASH###> }
}
}
[end]
In both language FE i get English-footer.
I also tried Different function of siteLanguage like
siteLanguage("navigationTitle")
siteLanguage("locale")
siteLanguage("hreflang") etc..
What i am doing wrong ?
Thanks in advance!
I get the following error in Typoscript Object Browser
Errors and warnings
Warning : Line 5696: Object Name String, "[siteLanguage" contains invalid character "[". Must be alphanumeric or one of: "_:-/." Show details
Warning : Line 5718: Object Name String, "[END]" contains invalid character "[". Must be alphanumeric or one of: "_:-/." Show details
Warning : Line 5719: Object Name String, "[siteLanguage" contains invalid character "[". Must be alphanumeric or one of: "_:-/." Show details
Warning : Line 5741: Object Name String, "[END]" contains invalid character "[". Must be alphanumeric or one of: "_:-/." Show details
In general, you should avoid conditions whenever possible. Conditions are evil!
Conditions are checked for each and every page request - before any cached content is touched. extensive use of conditions will be a performance killer.
For more details, search for "typo3 condition performance"
Using TypoScript if
A better way would be using the if-function, which is cachable, in combination with getText siteLanguage.
page.10 = TEXT
page.10.data = siteLanguage:languageId
page.10.stdWrap.wrap = <p>siteLanguage:languageId=|</p>
page.20 = IMAGE
page.20 {
if.value = 1
if.equals.data = siteLanguage:languageId
file = EXT:example/Resources/Public/typo3_package_de.png
}
page.30 = IMAGE
page.30 {
if.value = 0
if.equals.data = siteLanguage:languageId
file = EXT:example/Resources/Public/typo3_package_en.png
}

Use split within split in Typoscript?

Using typoscript, how do I split a field by linebreak and then split each line by : ?
This is what I have tried:
30 = TEXT
30.stdWrap {
field = abstract
split {
token.char = 10
wrap = <p>|</p>
1.current = 1
1.stdWrap.split {
token = :
wrap = <span>|</span>
}
}
}
Maybe, it's worth a look at dataProcessing...
There is also a CommaSeparatedValueProcessor which can provide CVS-like data prepared as single values for use in Fluid.
split works with some global properties, so, nesting split results into interference with values from previous split. I prefer using individual ContentObjects:
page.10 = COA
page.10.10 = LOAD_REGISTER
page.10.10.splitParts = vorname:stefan,nachname:froemken
page.10.10.splitParts.split {
token = ,
1.current = 1
}
page.10.20 = TEXT
page.10.20.data = REGISTER:splitParts
page.10.20.wrap = <p>|</p>
page.10.20.split {
token = :
wrap = <span>|</span>
1.current = 1
}
page.10.30 = RESTORE_REGISTER
Stefan

How to escape variables in Typoscript setup?

I'm trying to wrap an image with additional HTML elements and parameters, using Typoscript in a Setup Template.
So far, I've managed to wrap elements with HTML, but I'd like to add some parameters as well. The problem occurs, when I try to escape variables in variables - I can't pass UID from one of the parameters.
Below is the sample:
lib.parseFunc_RTE {
tags.img = TEXT
tags.img {
current = 1
preUserFunc = Netresearch\RteCKEditorImage\Controller\ImageRenderingController->renderImageAttributes
dataWrap = |
}
}
The problematic part is here: title="file:{parameters:data-htmlarea-file-uid}:title"
I've tried using {file:{parameters:data-htmlarea-file-uid}:title}, but it still doesn't work and shows error within rendered element:
The only working example is when I hardcode the UID ({file:120:title}), but it should be added dynamically, as there are many images.
How can I escape this "double variables"? Or maybe there is another solution to make it work?
==================================================
Here's the full solution of my problem, thanks to #Jo Hasenau
lib.parseFunc_RTE {
tags.img = COA
tags.img {
10 = TEXT
10 {
dataWrap = file:{parameters:data-htmlarea-file-uid}:title
wrap3 = <a href="{parameters:src}" class="lightbox" title="{|}"
insertData = 1
}
20 = TEXT
20 {
dataWrap = file:{parameters:data-htmlarea-file-uid}:description
wrap3 = data-lightbox-caption="{|}" data-lightbox-width="{parameters:width}" data-lightbox-height="{parameters:height}" rel="lightbox-group">
insertData = 1
}
30 = TEXT
30 {
current = 1
preUserFunc = Netresearch\RteCKEditorImage\Controller\ImageRenderingController->renderImageAttributes
wrap = |</a>
}
}
}
You can use dataWrap and/or insertData multiple times either by using the official order of stdWrap functions or by squeezing in another "level" of stdWrap functions with stdWrap.functionName
In this case it's the order of functions combined with a COA to separate the original wrap into smaller chunks and some additional braces provided by another wrap.
lib.parseFunc_RTE {
tags.img = COA
tags.img {
10 = TEXT
10 {
preUserFunc = Netresearch\RteCKEditorImage\Controller\ImageRenderingController->renderImageAttributes
dataWrap = file:{parameters:data-htmlarea-file-uid}:title
wrap3 = <a href="{parameters:src}" class="lightbox" title="{|}" data-lightbox-caption="{file:120:title}" data-lightbox-width="{parameters:width}" data-lightbox-height="{parameters:height}" rel="lightbox-group">
insertData=1
}
20 = TEXT
20.current = 1
20.wrap = |</a>
}
}
preUserFunc will be executed first, then the first dataWrap will create the actual variable name, followed by wrap3 to get the necessary curly braces, finalized by insertData to fill in all the other variables together with the generated variable.
The order in this code is just for better readability, but the actual order of function calls within stdWrap is predefined in the PHP code and follows exactly the order of function descriptions in the official docs: https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Functions/Stdwrap.html

Assign register value to TYPO3 CASE key

Am making some complex menus and would like to use CASE (or similar) to determine the number of submenus in a given branch in order to determine the style of menu to use.
Code:
5 = HMENU
5 {
entryLevel = -1
1 = TMENU
1 {
expAll = 1
NO = 1
NO {
...
}
IFSUB = 1
IFSUB {
10 = CASE
10 {
key.data = {register:count_menuItems}
1 = COA
1 {
data = {field:title}
data.insertData = 1
}
2 = COA
2 {
data = {field:title}
data.insertData = 1
}
default = COA
default {
data = {field:title}
data.insertData = 1
}
}
wrapItemAndSub = |
}
}
2 = TMENU
2 {
maxItems = 2
expAll = 1
...
}
}
How can I get CASE to work? I've tried it with and without the braces.
you should get more information how to access fields, register and other data in typoscript.
if you have a property you mostly can modify the way to get other information than a constant text.
In your example it is the key property where constants are not meaningful.
if you want to access a field of the 'current' record/data you just use key.field = fieldname
if it is other data you modify it to key.data = register:registername
accessing a field can be done with key.data = field:fieldname
If you want these data connected to other information you could use a wrap:
key.data = register:registername
key.wrap = prefix- | -suffix
Notice: the parts of the wrap are trimmed before they are connected
another way would be an inline notation where you even can use multiple values:
key = {register:registername}-with-{field:fieldname}
key.insertData = 1
here you have two replacements. each has to be wrapped in braces {} and you need to tell TYPO3 that there are replacements to do: insertData = 1
special case TEXTobject:
10 = TEXT
10.value = constant Text
20 = TEXT
20.field = fieldname
30 = TEXT
30.data = register:registername
40 = TEXT
40.value = register is '{register:registername}' and field is '{field:fieldname}'
40.insertData = 1
ADDED:
see the manual of the typoscript data type getText where you can find what else can be used instead of register:
then the manual entry for data which is a property of the function .stdWrap and of type getText.
This entry is followed by the property field stating, it is a shortcut for data = field:
(This explaines why your COA with .data results in anything, as doing a .stdWrap.data on any object will replace the object's content.)
be aware that field (either as property or as key of getText) will select
a field of the current record, which might vary dependent on context:
for page rendering it is the record of the current page (table pages),
for rendering a content element it is the element (table tt_content),
inside a filesProcessor it is a file (table sys_file_reference`),
in the renderObj of CONTENT, RECORDS, or split it is the selction you define.
Found the answer. As far as I can tell, CASE works on stdwrap.cObjects and so the code
10 = CASE
10 {
key.data = {register:count_menuItems}
...
}
should be
stdWrap.cObject = CASE
stdWrap.cObject {
key.data = register:count_menuItems
if.isTrue.data = register:count_menuItems
...
}
This way it works.

Typoscript operators - Value of filelink referencing to another one

I've set up the Typoscript below, but the last line doesn't work.
I want 20.filelink to have the same content as 10.filelink (the real code is more complex and that bit is redundant).
lib.test = COA
lib.test {
10 = TEXT
10.value = A value
10.filelink {
path = fileadmin/path/
target = blank
stdWrap.wrap = <li>|</li>
}
20 = TEXT
20.if.isFalse.data = subheader
20.value = Another value
20.filelink =< lib.test.10.filelink
}
Copying (with the < operator) works, but not =< as stated.
I've also tried without the lib.test. or with just = but without any success.
Is what I want to do possible?
What did I not understand about operators?
you should put it out of the curly brackets :
lib.test = COA
lib.test {
10 = TEXT
10.value = A value
10.filelink {
path = fileadmin/path/
target = blank
stdWrap.wrap = <li>|</li>
}
20 = TEXT
20.if.isFalse.data = subheader
20.value = Another value
}
lib.test.10.filelink =< lib.test.20.filelink
I figured out what I did not understand. Apparently, you can only copy or reference Content Objects.
The answer then is to reference the entire object, and to modify and add what needs changing. In this case it would be:
lib.test = COA
lib.test {
10 = TEXT
10.value = A value
10.filelink {
path = fileadmin/path/
target = blank
stdWrap.wrap = <li>|</li>
}
20 = < lib.test.10
20.if.isFalse.data = subheader
20.value = Another value
}