Typo3 inherit data when if is true - typo3

I generate an lib.content with the current content but i want to add it only if the following if statement will be true, otherwise not/empty:
lib.content = COA
lib.content{
10 < styles.content.get
10.stdWrap.cObject.if{
value.data = DB:pages:{page:uid}:nav_hide
value.data.insertData = 1
equals = 1
}
}
is this possible or where's the error in the syntax?
Version of Typo3 is 10.4

You need to use "insertData" twice, because it replaces {page:uid} with the UID (e.g. 5), but it keeps the rest DB:pages:5:nav_hide.
The rest DB:pages:5:nav_hide needs to be "data inserted" again, so the trick is to use wrap3.
Solution:
lib.content = COA
lib.content {
10 < styles.content.get
10.stdWrap.cObject.if {
// Replaces page:uid
value.dataWrap = DB:pages:{page:uid}:nav_hide
// Wraps curly brackets around DB:pages:5:nav_hide
value.wrap3 = {|}
// Replaces DB:pages:5:nav_hide with the nav_hide value
value.insertData = 1
equals = 1
}
}

Related

Pass a variable to a content object containing a tx_news plugin

This is very similar to my question Counter for mask elements in a TYPO3 column
I need to pass a variable (in my case, the value of cObj:parentRecordNumber which is the counter for the current item in it's column) to the template.
In the main page template:
<f:cObject typoscriptObjectPath="lib.content.pageteasers" />
In typoscript:
lib.content {
pageteasers < styles.content.get
pageteasers {
select {
where = colPos=2
max = 8
}
// this passes the variable elementCounter to the fluid template of the rendered mask content element:
renderObj.mask_teaser {
variables {
elementCounter = TEXT
elementCounter.value = {cObj:parentRecordNumber}
elementCounter.insertData = 1
}
}
// this should pass the same value to a rendered tx_news plugin:
variables {
elementCounter = TEXT
elementCounter.value = {cObj:parentRecordNumber}
elementCounter.insertData = 1
}
// it doesn't. what about these trial & error:
renderObj.list < .variables
renderObj.plugin.tx_news < .variables
renderObj.list.20.news_pi1 < .variables
renderObj.news_pi1 < .variables
// none of these seem to work either
}
}
And then in the rendered CE template (News/List.html)
<f:debug title="" inline="1">{_all}</f:debug>
I don't manage to see the above variable in here. What is the correct way to pass the variable from TS to the news fluid template?
PS Another try was using the Good Old Register
pageteasers < styles.content.get
pageteasers {
select {
where = colPos=2
max = 8
}
append = LOAD_REGISTER
append {
elementCounter = TEXT
elementCounter.value = {cObj:parentRecordNumber}
elementCounter.insertData = 1
}
}
And in the template:
{v:variable.register.get(name: 'elementCounter')}
but that is NULL
Your try via register could work. But you have to care, where you are doing what...
Registers
LOAD_REGISTER is of type string/stdWrap and not a cObject per definition. If you wanna use content based on a cObject, you can declare this via the stdWrap-property (as shown in the examples):
1 = LOAD_REGISTER
1.param.cObject = TEXT
1.param.cObject.stdWrap.data = GP:the_id
So, in your case it should like:
elementCounter.cObject = TEXT
elementCounter.cObject.data = cObj:parentRecordNumber
Appending at the right place
You are trying to use append directly as a property of pageteasers (which is a copy of styles.content.get which is of type CONTENT.
CONTENT does not have an append-property. In addition, you would put the register in front of the entire content, not the individual content elements.
=> It's needed as part of the renderObj, so it's rendered per CE.
The renderObj of CONTENT is of type CASE, which also has no stdWrap-properties directly. But it has a property stdWrap with stdWrap-properties...
Conclusion
So, you can end up with this snippet:
lib.content {
pageteasers {
renderObj {
stdWrap {
append = LOAD_REGISTER
append {
elementCounter.cObject = TEXT
elementCounter.cObject.data = cObj:parentRecordNumber
}
}
}
}
}

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
}

TypoScript: conditional wrap if more than one item

hmm... my TypoScript skills seem to have become a bit rusty.
lib.feld < styles.content.get
lib.feld.select.orderBy = rand()
lib.feld.select.select.where = colPos=11
lib.feld.wrap = <div class="wrapper">|</div>
I would like to add the wrapper div only if styles.content.get returns more than one item for said colPos.
I've tried the following two variants:
lib.feld.wrap.if {
isGreaterThan.numRows < styles.content.get
isGreaterThan.numRows.select.where = colPos=11
value = 1
}
and
lib.feld.wrap.if {
isGreaterThan.numRows.table = tt_content
isGreaterThan.numRows.select < styles.content.get.select
isGreaterThan.numRows.select.where = colPos=11
value = 1
}
also with an additional stdWrap before numRows.
Everything returns false, even when there should be multiple results.
What is wrong?
from typoscript definition I would guess:
temp.feld < styles.content.get
temp.feld.select.where = colPos=11
temp.feld.select.orderBy = rand()
temp.feld.select.pidInList = 123
lib.feld < temp.feld
lib.feld.wrap = <div>|</div>
lib.feld.wrap.if {
isGreaterThan.stdWrap.numRows < temp.feld
value = 1
}
for inspecting/debuggung the value of numRows you might use this:
lib.numRows = TEXT
lib.numRows.numRows < temp.feld
lib.numRows.wrap = numRows=[|]
which you can use in fluid
{f:cObject(typoscriptObjectPath:'lib.numRows')}
or in typoscript itself for output
page.3 < lib.numRows

typo3 css_styled content edit source

I have the following problem:
I am using typo3 4.7.7 and I am adding custom columns in the Backend. I am able to do taht by place a configuration array in the /typo3conf/extTables.php
$TCA["tt_content"]["columns"]["colPos"]["config"]["items"] = array (
"3" => array ("Border,"3"),
"2" => array ("Right","2"),
"1" => array ("Left","1"),
"0" => array ("Normal","0"),
"5" => array ("Central","5"),
"6" => array ("Border","6"),
"4" => array ("Footer","4")
);
Then set:
mod.SHARED.colPos_list=0,1,2,3,4,5,6
in the TSconfig.
It is working, I enjoy my new columns :), but there is a problem. I want to be able to use the css_styled_content to map my new columns to my html template. This is not possible, because the "get" constants of css_styled_content are hard coded and I am not able to use something like "content.getFooter". At the moment the only way I can get my content is like this:
...
page.10 = CONTENT
page.10.table = tt_content
page.10.select {
orderBy = sorting
where = colPos = 4
}
page.10.renderObj = COA
page.10.renderObj {
10 = TEXT
10.field = header
20 = TEXT
20.field = bodytext
}
...
This is a lot of code, so I was wondering if there is a way to "make" CSC recognize my new columns, so that I would be able to use "content.getMYCUSTOM_COLUMN_NAME".
P.S. I do not want to use templavoila and I found something in the source of CSC under /static/setup.txt :
# Clear out any constants in this reserved room!
styles.content >
# get content
styles.content.get = CONTENT
styles.content.get {
table = tt_content
select.orderBy = sorting
select.where = colPos=0
select.languageField = sys_language_uid
}
# get content, left
styles.content.getLeft < styles.content.get
styles.content.getLeft.select.where = colPos=1
# get content, right
styles.content.getRight < styles.content.get
styles.content.getRight.select.where = colPos=2
# get content, margin
styles.content.getBorder < styles.content.get
styles.content.getBorder.select.where = colPos=3
# get news
styles.content.getNews < styles.content.get
styles.content.getNews.select.pidInList = {$styles.content.getNews.newsPid}
# Edit page object:
styles.content.editPanelPage = COA
styles.content.editPanelPage {
10 = EDITPANEL
10 {
allow = toolbar,move,hide
label.data = LLL:EXT:css_styled_content/pi1/locallang.xml:eIcon.page
label.wrap = | <b>%s</b>
}
}
I then tried to add:
# get content, footer
styles.content.getFooter < styles.content.get
styles.content.getFooter.select.where = colPos=4
But it did not work.
you are on the right track. try to create your own Content Object:
temp.footer < styles.content.get
temp.footer.select.where = colPos=4
page = PAGE
page.100 < temp.footer