Is it possible to use variables defined in TypoScript in TypoScript conditions?
For example if I define a variable like this:
my_var = 10
Can I create a condition in typoscript that checks if my_var equals 10?
I imagine something like this:
my_var = 10
[my_var = 10]
# do something
[else]
# do something else
[end]
The reason why I need this is the lack of nested conditions. If what I'm asking for is possible, I can do something like this to overcome this limitation:
[globalVar=TSFE:id=1]
# render special layout for page 1
[else]
normal_layout = 1
[end]
[normal_layout = 1] && [globalVar=TSFE:page|layout=1]
# render normal layout 1
[end]
[normal_layout = 1] && [globalVar=TSFE:page|layout=2]
# render normal layout 2
[end]
Another usecase would be to check for the existence of a variable, for example if page was already defined. Example:
[globalVar=TSFE:id=1]
page = PAGE
page.10 = TEXT
page.10.value = hello page 1!
[end]
[!page]
page = PAGE
page.10 = TEXT
page.10.value = hello world!
[end]
I'm surprised that the docs don't answer this already :S
edit
I've tried Andreas Ottos solution, but it still does not seem to work. Here's my example code:
lib.content = TEXT
lib.content.value = this text should not get displayed
[globalVar=TSFE:id=1]
lib.content = TEXT
lib.content.value = this is page 1
[else]
normal_layout = 1
[end]
[globalVar = LIT:1 = {$normal_layout}]
lib.content = TEXT
lib.content.value = this is any other page
[end]
page = PAGE
page.10 < lib.content
In theory, this should render 'this is page 1' for page 1 and 'this is any other page' for any other page. But while page 1 gets rendered correctly, this is not the case for the other pages. They get rendered with 'this text should not get displayed'.
Any ideas? I'm using version 7.6. Is that maybe the problem?
EDIT: For the first UseCase:
It is possible with a TypoScript "literal". See a small hint in the doc here.
And you have to separate the constants from the logic.
So in the constants you have to write:
[globalVar=TSFE:id=1]
normal_layout = 0
[else]
normal_layout = 1
[end]
And in the setups part you can use this variable:
[globalVar = LIT:0 = {$normal_layout}]
# render special layout for page 1
[end]
[globalVar = LIT:1 = {$normal_layout}] && [globalVar=TSFE:page|layout=1]
# render normal layout 1
[end]
[globalVar = LIT:1 = {$normal_layout}] && [globalVar=TSFE:page|layout=2]
# render normal layout 2
[end]
Your second usecase is not really clear but I would recommend to use a base definition of page which is overwritten in the specific cases.
Related
How do I use conditions to put different headerdata on the home page and 3 other pages using typoscript?
I have tried this:
page {
[treeLevel = 0]
headerData.20.value = Home Page
[END]
[page|uid = 1]
headerData.20.value = Page 1
[END]
[page|uid = 2]
headerData.20.value = Page 2
[END]
[page|uid = 3]
headerData.20.value = Page 3
[END]
}
But the home page outputs Page 3
I have also tried [globalVar = TSFE:id = X] with the same result.
And the object Browser says [ is an invalid character?
According to documentation (thanks to #BerndWilkeπφ for reminding), TypoScript conditions must be placed on top level of your TS (outside of any other structures).
Not in any cObject like page, neither within other conditions.
I realised the problem is because I nested the conditions inside page.
After taking them out it all works fine.
For some pages with the event list plugin from EXT:cal the cache should be deleted every midnight. I did this typoscript code in template file:
[globalVar = TSFE:id=4010, TSFE:id=3749, TSFE:id=5217, TSFE:id=4123]
config.cache_clearAtMidnight = 1
[GLOBAL]
Unfortunely this does not work in TYPO3 CMS 7.6.19. How can I delete cache at midnight for some pages?
"Clear at midnight" means that upon writing the page cache entry, the timeout is set to seconds-until-midnight (typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php get_cache_timeout()).
Maybe you just have to clear the frontend cache.
Btw, the TypoScript condition is ok but could be made much shorter.
https://docs.typo3.org/typo3cms/TyposcriptReference/Conditions/Reference/Index.html#id45
Adapt your TS condition according to TS reference https://docs.typo3.org/typo3cms/TyposcriptReference/Conditions/Reference/Index.html#id45
[globalVar = TSFE:id = 4010|3749|5217|4123]
config.cache_clearAtMidnight = 1
[GLOBAL]
This will match, if the page-id is equal to either 4010, 3749, 5217 or 4123.
On my page config.cache_period = 604800 is set. In this case the condition content has to be expanded:
[globalVar = TSFE:id = 4010|3749|5217|4123|1861|1495|221|1372|3142|3994|4390]
config.cache_period = 86400
config.cache_clearAtMidnight = 1
[GLOBAL]
I report this as a core bug: https://forge.typo3.org/issues/82380
I'm struggling with a simple Breadcrumb Navigation in Typoscript. I just want a simple link to the higher-level page. So if you're on page-3 there should be a link to page-2, if on page-4 there should be a link to page-4 and so on.
I've already been testing different special.range parameters. None of them worked for me.
From docs:
If the value is < 0, entryLevel is chosen from "behind" in the rootLine. Thus "-1" is a menu with items from the outermost level, "-2" is the level before the outermost...
In rootline menu that means the -1 level is current page, -2 one level above current, etc. so linking only parent level is as simple as:
lib.linkOneLevelAbove = HMENU
lib.linkOneLevelAbove {
special = rootline
special.range = -2|-2
1 = TMENU
1.NO = 1
}
page.1 < lib.linkOneLevelAbove
I have two forms on my page.
I want to change the target of a form with typoscript. The result should be two different "Thank You for contacting me" pages for two different forms on one site.
I've tried the following Typoscript
[globalVar = GP:tx_powermail_pi1|uid55 = 1]
plugin.tx_powermail_pi1.formaction.typolink.parameter = 299
[else]
plugin.tx_powermail_pi1.formaction.typolink.parameter = 258
[end]
In this case I've made a hidden field with the UID 55 and the value 1.
and the second try:
[globalVar = GP:tx_powermail_pi1|mailID < 1613]
plugin.tx_powermail_pi1.formaction.typolink.parameter = 299
[else]
plugin.tx_powermail_pi1.formaction.typolink.parameter = 258
[end]
In this case I simply check the mailID of the posted form (ID 1612 is form number 1 and ID 1618 is form number 2).
but it does not work. In both cases the target is the page with the id 258.
I've also tried the same with globalString.
Typo3 4.6.7 with powermail 1.6.10
If you just want different "Thank you" pages for both forms, then use "Auto-redirect after confirmation-page", which can be found in the plugin-settings (tab "Answer page") of your Powermail forms.
How would one go about displaying the page content as a list of previews pointing to individual content elements, instead of just displaying them all at once? I will be grateful even for just a conceptual answer.
For creating a menu of content elements you can use the content type menu, set the menu type to section index and select a page.
You can of course modify the output by manipulating the TypoScript.
Here an example that adds parts of the bodytext field and an image. The latter is not tested and written in pseudo TypoScript ;-)
tmp < tt_content.menu.20.3.renderObj
page.5 < tt_content.menu.20.3
page.5.renderObj >
page.5.renderObj = COA
page.5.renderObj {
wrap < tmp.wrap
stdWrap.typolink < tmp.typolink
10 < tmp
10.wrap >
10.typolink >
20 = TEXT
20.field = bodytext
20.parseFunc < lib.parseFunc_RTE
20.cropHTML = 100
30 = IMAGE
30.file.import.field = image
30....
}