1
votes

I use Typo3 1.4.10, using the Bootstrap package

I try to change a Typo3 fluid template based on the current front-end language being used. I have tried various "if conditions". I just cannot figure it out. I have tried using siteLanguage, language and sys_language_uid. In the TSsetup siteLanguage works for me as in:

[siteLanguage("locale") == "en_US.UTF-8"]
 ...

[global]

I cannot figure out is how to do something similar in the fluid templates. I tried tons of different ways. How can I correct the below example taken from one of my many attempts?

<f:if condition="{siteLanguage} == {siteLanguage.locale}">
<f:if condition="{siteLanguage.locale} == en">
 <f:then>
    language 1
</f:then>
<f:else>
    language 0
</f:else>
</f:if> </f:if>
3

3 Answers

1
votes

You can use a vhs viewhelper

  <html data-namespace-typo3-fluid="true"
          xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
          xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers">


<f:if condition="{v:page.language()}==0">
  <f:then>
      language 0
  </f:then>
  <f:else>
      other language
  </f:else>
</f:if>
</html>

Therefore you have to install the extension vhs first.

0
votes

If it works for you in the TypoScript setup, you should use that to either switch the template file or to provide a variable containing the language information.

Doing this within the Fluid template itself will increase the processing load, especially if you try solving it with a ViewHelper.

Switching the template and/or layout with TypoScript would be recommended IMHO, since you could still go for the same partials to avoid redundant code but had to check the condition just once.

0
votes

there are 2 approaches, which I also used in my latest projects. I hope this helps you and others, too.

1. Defining a simple string variable for the PAGE's fluid template

This is the code for your TypoScript setup.

// Setting a default value
page.10.variables.currentLanguage = TEXT
page.10.variables.currentLanguage.value = default

// Change value to English
[siteLanguage("locale") == "en_US.UTF-8"]
page.10.variables.currentLanguage.value = english
[global]

// Change value to German
[siteLanguage("locale") == "de_DE.UTF-8"]
page.10.variables.currentLanguage.value = deutsch
[global]

2. Defining one (ore more) value/s for the fluid templates settings

This is the code for your TypoScript setup.

// Setting a default value
page.10.settings.currentLanguage = default

// English
[siteLanguage("locale") == "en_US.UTF-8"]
page.10.settings.currentLanguage = english
[global]

// German
[siteLanguage("locale") == "de_DE.UTF-8"]
page.10.settings.currentLanguage = deutsch
[global]

Switch the Fluid template, depending on your language value

In your fluid template you should use a switch statement like this:

<f:switch expression="{currentLanguage}">
    <f:case value="english">
        <!-- English content -->
    </f:case>
    <f:case value="deutsch">
       <!-- German content -->
    </f:case>
    <f:defaultCase>
       <!-- Default content -->
    </f:case>
</f:switch>

<!-- When using the settings, you need to use: -->
<f:switch expression="{settings.currentLanguage}">
...

Further questions? Feel free to ask!