0
votes

I'm running a Typo3 v9.5.4 Onepager style Website. The content is loaded directly from the tt_content. The Website has two FE languages (German/English). I have a CTA button which has an anchorlink. The button is create with typoscript. I created one button for the German version and one for the English verson bc they have another value and another ancorlink.

I'm not sure if I can access a tt_content field directly from a fluid viewhelper. This is my code i've tried

        <f:if condition="{tt_content.sys_language_uid} == 1">
          <f:then>
              <f:format.raw>{buttonEn}</f:format.raw>
          </f:then>
          <f:else>
              <f:format.raw>{buttonDe}</f:format.raw>
          </f:else>
        </f:if>

This is my Typoscript for the two button Objects

lib.buttonDe = TEXT
lib.buttonDe {
    value = German Text
    stdWrap.typolink.parameter = #anchorlinkDE
    stdWrap.typolink.ATagParams = class="button"
}

lib.buttonEn = TEXT
lib.buttonEn {
    value = English Text
    stdWrap.typolink.parameter = #anchorlinkEN
    stdWrap.typolink.ATagParams = class="button"
}

And this is the typoscript that loads the Content, the Languages Menu and the Fluidtemplate (the Onepager Content is loaded without a Fluidtemplate, it loads the content directly from tt_content):

//--------------------- One Pager Content

lib.sectionContent = HMENU
lib.sectionContent {
  excludeUidList = 12,13,16,17,29
  1 = TMENU
  1 {
    NO = 1
    NO {
      doNotLinkIt = 1
      stdWrap >
      stdWrap {
        cObject = COA
        cObject {
          if.value = 4
          if.equals.field = doktype
          if.negate = 1
          10 < temp.titleSectionId
          10.wrap = <section id="|">
          20 = CONTENT
          20 {
            table = tt_content
            select {
              pidInList.field = uid
              orderBy = colPos,sorting
              # Only selects Content where CE Layout is 0
              where = (tt_content.layout = "0") 
            }

            wrap = <div class="container">|</div>
            renderObj < tt_content
          }
          30 = TEXT
          30 {
            wrap = </section>
          }
        }
      }
    }
  }
}

//---------------------

// Language Selector
lib.langmenu = HMENU
lib.langmenu {
    special = language
    addQueryString = 1
    special.value = {$config.language.uids}
    1 = TMENU
    1 {
        wrap = <ul class="dg-langmenu row">|</ul>
        NO = 1
        NO {
            stdWrap.current = 1
            stdWrap.setCurrent = {$config.language.labels}
            allWrap = <li class="col s6">|</li>
        }

        ACT < .NO
        ACT.doNotLinkIt = 1
        ACT.allWrap = <li class="act col s6">|</li>
    }
} 


page = PAGE
page{
    10 = FLUIDTEMPLATE
    10 {

        templateName = TEXT
        templateName.stdWrap{
            cObject = TEXT
            cObject{
                data = levelfield:-2,backend_layout_next_level,slide
                override.field = backend_layout
                split {
                    token = pagets__
                    1.current = 1
                    1.wrap = |
                    }
            }  
        ifEmpty = onePager
        }

    templateRootPaths {
    10 = {$path.privat}Templates/
    }
    layoutRootPaths {
        10 = {$path.privat}Layouts/
    }
    partialRootPaths {
        10 = {$path.privat}Partials/
    }

    variables{
    buttonDe < lib.buttonDe
    buttonEnd< lib.buttonEn
    }


}

So I'd like to load the buttonEn if the content has the sys_language_uid 1 (English) else I want it to load the buttonDe.

Do I need to create an Typoscript Object and then load this Object into the f:if viewhelper? If so how do I create this Typoscript Object.

Thanks for your help!

2
Can you post your TypoScript please?Thomas Löffler
I've added the TypoScript to my post.Eluvitie

2 Answers

0
votes

You should use a locallang file and refer to it in TypoScript.

  1. Create a locallang file (copy an existing and remove all values) named locallang.xlf
  2. Add your english label in there
  3. Create a locallang file in the same folder with prepending de. in the filename (de.locallang.xlf) and add the german label
  4. Refer to it in the TypoScript by using lib.button.data = LLL:EXT:your_ext/path/to/locallang/locallang.xlf:buttonLabel, see https://docs.typo3.org/typo3cms/TyposcriptReference/DataTypes/Index.html#lll

This TS getText function gets the label depending on the set language ID automatically and you only need one TS for the button.

Example: https://docs.typo3.org/typo3cms/TyposcriptIn45MinutesTutorial/UsingGetText/Index.html

0
votes

The easy way (pure typoscript)

lib.button = TEXT
lib.button {
    value = English text
    lang.de = Deutscher Text
    stdWrap.typolink.parameter = #anchorlinkDE
    stdWrap.typolink.ATagParams = class="button"
}
[siteLanguage("locale") == "en_EN.UTF-8"]
  lib.buton.stdWrap.typolink.parameter = #anchorlinkEN
[global]

but the professional solution is configuring your labels in a language file (see answer from Thomas Löffler) and use:

lib.button = TEXT
lib.button {
    lib.button.data = LLL:EXT:site_extension/Resources/Private/Language/locallang.xlf:button_label
    stdWrap.typolink.parameter = #anchorlinkEN
    stdWrap.typolink.ATagParams = class="button"
}
[siteLanguage("locale") == "de_DE.UTF-8"]
  lib.buton.stdWrap.typolink.parameter = #anchorlinkDE
[global]

For language dependent constant data you might use typoscript conditions to redefine a value for your non default languages. (or define a fallback and conditions for each language.)