Adding a language selection

dleinich
Occasional Collector
1 2 655

In projects using multiple languages it is often desired to display a list of available languages for a given page and link to them.

You can get a list of all defined languages for a project from the #global system object:

#global.project.languages

Please note that you should always check if a given language should actually be generated. This check can easily be done using the .shouldGenerate() method on the list entries you get from #global.project.languages.

See the example below on how to render a list of all available languages for the current page and link to them.

<ul id="languages">

     $CMS_FOR(language, #global.project.languages)$

          $CMS_IF(language.shouldGenerate())$

               $CMS_IF(language == #global.language)$

                    <li class="selected"><a href="$CMS_REF(#global.ref, lang:language.abbreviation.upperCase)$">$CMS_VALUE(language.name)$</a></li>

               $CMS_ELSE$

                    <li><a href="$CMS_REF(#global.ref, lang:language.abbreviation.upperCase)$">$CMS_VALUE(language.name)$</a></li>

               $CMS_END_IF$

          $CMS_END_IF$

      $CMS_END_FOR$

</ul>  

Further information on the data type Language can be found in the FirstSpirit API documentation. Details on the system object #global are available in the online documentation.

2 Comments
Version history
Last update:
‎06-28-2010 08:11 AM
Updated by: