Search code examples
if-statementtypo3typoscripttypolink

typoscript conditional typolink-parameter


TS is confusing :)

I'm trying to create a typolink with a conditional parameter depending on the language.

10 = TEXT
  10 {
    typolink {
      parameter = http://myLink.com
      returnLast = url
      if.isTrue.data = GP:L = 1
    }
    wrap (
            <li class="mod-metanav--item">
             <a class="mod-metanav--link" target="_blank" href="|">
              The Link
             </a>
            </li>
    )
  }

As you can see, I tried to add an IF-statement to the typolink, asking for a language (at least, that's what I think I did).

The thing is, that, depending on the current language I want a different link (but the rest needs to remain the same).

I could use [globalVar = GP:L = 1] but that would create a HUGE overhead, since this typolink is just a fraction of a bigger script-part.

I tried to google for variables or constants that I could add to the parameter, but nothing gave me a useful result...

HELP! :)


Solution

  • To override the link value depending on the current language you may use the »lang« parameter.

    To change the link url depending on the current language you may want to use a CASE object…

    10 = TEXT
    10 {
        value = English
        lang.de = German
        lang.fr = French
        typolink.parameter.cObject = CASE
        typolink.parameter.cObject {
            key.data = GP:L
            1 = TEXT
            1.value = http://example.com/german/bar/
            2 = TEXT
            2.value = http://example.com/french/baz/
            default = TEXT
            default.value = http://example.com/englisch/foo/
        }
        typolink.ATagParams = class="mod-metanav--link"
        typolink.extTarget = _blank
        wrap = <li class="mod-metanav--item">|</li>
    }
    

    …or you use a constant:

    constants:

    languagedependentlink = http://example.com/englisch/foo/
    [globalVar = GP:L = 1]
        languagedependentlink = http://example.com/german/bar/
    [global]
    [globalVar = GP:L = 2]
        languagedependentlink = http://example.com/french/baz/
    [global]
    

    setup:

    10 = TEXT
    10 {
        value = English
        lang.de = German
        lang.fr = French
        typolink.parameter = {$languagedependentlink}
        typolink.ATagParams = class="mod-metanav--link"
        typolink.extTarget = _blank
        wrap = <li class="mod-metanav--item">|</li>
    }