Search code examples
typo3fluid

Display language icon in Fluid template


I would like to display the assigned language for each record by showing the respective language icon.

I plan to do this in a Fluid template in a BE module using TYPO3 8 with already existing TYPO3 icons.

I can read the value of sys_language_uid from the records.

The icons are already supplied by TYPO3, as I can see in the list of "Website Language" on pid=0.

I've also found a ViewHelper to do this .

So, what I have to do is something like:

  • From the value of sys_language_uid, read the correct code from sys_language.language_isocode (e.g. 'en', 'es')
  • Get the correct name for the icon from the isocode
  • Display the icon with the ` ViewHelper

Is there a ViewHelper that already does this? Do I have to write it from scratch? What is an efficient way to do this?


Solution

  • The main problem here is that there are no icons for languages. Please do not confuse languages with countries where usually flags are used as icons.

    Instead you should display the language in its language, so e.g. Deutsch for German.

    This can be achieved if you load the sys_language record referred to by the language field in the record (usually sys_language_uid). There are quite a few ways to deal with this and since you already use Fluid you could try to get started with the <v:resource.record/> viewhelper from the vhs TYPO3 extension:

    <v:resource.record
        table="sys_language"
        field="title"
        uid="{data.sys_language_uid}"
        as="languageTitle">
        {languageTitle}
    </v:resource.record>
    

    To have this applied to every record, you could copy and customize the Default.html layout of Fluid StyledContent and output the language of the processed record there.