I want to generate different images depending on the languages with TypoScript.
<img src="/specilized-nl.png" alt="logo">
<img src="/specilized-en.png" alt="logo">
<img src="/specilized-de.png" alt="logo">
So depending on the selected languages the correct image is shown by using a different image name. How could this be done?
use conditions on language parameter (most probably L)...
lib.myImage = <img src="/specilized-nl.png" alt="logo">
[globalVar = GP:L = 1]
lib.myImage = <img src="/specilized-en.png" alt="logo">
[global]
[globalVar = GP:L = 2]
lib.myImage = <img src="/specilized-de.png" alt="logo">
[global]
Of course I assume in that sample, the NL is default, EN has uid 1, and DE has uid 2, fix it to reflect your real situation.
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.
Is it possible to change the l10n_mode of a field (e.g. assets) based on the CType, layout or PageTree?
Use case:
Default l10n_mode of assets is 'exclude' (set by a site package extension)
For a specific CType it's necessary to change the assets field in translations (to allow translation of captions)
In TYPO3 7.6 the following was possible:
[PIDinRootline = 173]
config.sys_language_softMergeIfNotBlank = tt_content:assets
[end]
EDIT
sys_language_softMergeIfNotBlank
was removed in TYPO3 8.7, so this is not possible anymore. Breaking Change
In TYPO3 8.7 you can use below typoscript condition.
For Page Layout.
[page|layout = 1]
config.sys_language_softMergeIfNotBlank = tt_content:assets
[end]
For pageTree.
[treeLevel = levelnumber, levelnumber, ...]
config.sys_language_softMergeIfNotBlank = tt_content:assets
[end]
For Ctype
[page|field = value]
config.sys_language_softMergeIfNotBlank = tt_content:assets
[end]
For more typoscript condition Click Here
With these TypoScript settings you can set the global language handling:
config.sys_language_mode = strict
config.sys_language_overlay = hideNonTranslated
Now, I want some records (from my own extension) to behave different, I need sys_language_mode=content_fallback and sys_language_overlay=0.
Is there a possibility to set a different language handling for specific records or extensions?
You can try to config it inside a condition.
[globalVar = GP:tx_myext_pi1|showUid > 0]
config.sys_language_mode = content_fallback
config.sys_language_overlay = 0
[GLOBAL]
See https://docs.typo3.org/typo3cms/TyposcriptReference/8.7/Conditions/Reference/Index.html#globalvar
You can Try below typoscript condition for specific plugin of your custom extension.
[globalVar = TCEFORM.tt_content.layout = 1] // Here you can select specific layout
config.sys_language_mode = content_fallback
config.sys_language_overlay = 0
[global]
Also You need to select specific layout(in content appearance Tab) for this plugin.
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.
<g:Grid>
<g:row>
<g:customCell>
<g:HTMLPanel styleName="{style.loginPrompt}">
<div>
<ui:msg description="LoginPrompt">Please <b>Log In</b></ui:msg>
</div>
</g:HTMLPanel>
</g:customCell>
</g:row>
...
I want that my cell text will be in second cell like in java:
Grid g = new Grid(5, 5);
g.setText(0, 1, "asdf");
If you want 5 rows and 5 columns, I think you have to define them all in the UiBinder using the appropriate number of g:row and g:cell (or g:customCell). There's no equivalent to setText but you can do the equivalent of setHTML by using a g:cell (and g:customCell is equivalent to setWidget).
<g:Grid>
<g:row>
<g:customCell><!-- whatever --></g:customCell>
<g:cell>asdf</g:cell>
<!-- continue here for 5 rows, 5 cells per row -->