• ♡ Sponsor

    Multilingual Content

    #Session

    In case you want to provide your content in multiple languages, it is important that once a user has selected a language, the selection persits across multiple pages. Automad provides an easy way to store such data in the session data array. The saved selection will then be used for all following requests to serve the corresponding content. Take a look at the session template for a detailed example.

    Saving the Language Selection

    Assuming that the language selection is passed as a query string parameter with the name lang, it can be saved in the session data array like this:

    <@ if @{ ?lang } @>
        <@ set { %lang: @{ ?lang } } @>
    <@ end @>
    

    Now the language selection is saved in the %lang session variable and can be used in the current and in future requests.

    Serving the Corresponding Content

    In a second step, a simple conditional statement can be used to serve the corresponding content.

    <@ if @{ %lang } = 'de' and @{ textGerman } @>
        @{ textGerman | markdown }
    <@ else @>
        @{ textEnglish | markdown }
    <@ end @>
    

    Related

    Template Language  ⁄
    Variables — Template Language

    The actual value of a variable is depending on the current context. In most cases the context is the currently requested page. However, control structures can change the context to any other page during runtime, for example when iterating over a list of pages. In case a variable ...

    Toolbox  ⁄
    set — Toolbox

    Sets shared, session or runtime variables by passing key/value pairs as option array.

    • Automad
    • Developer Guide
    • Building Themes
    • Template Language
    • Multilingual Content
    Discuss
    Packages
    Release Notes
    Support
    Terms of Use
      Become a Sponsor
      GitHub
      Twitter
      Facebook
      Instagram
      2013-2022 by Marc Anton Dahmen
    Released under the MIT license

    A faceless machine, creating one's portrait in the internet.
  • Automad
  • Getting Started
  • System
  • User Guide
  • Developer Guide
  • Headless Mode
  • Discuss
  • Packages
  • Developer Guide ←
  • Building Themes ←
  • Template Language
  • Variables →
  • Pipe →
  • Toolbox →
  • Objects →
  • Control Structures →
  • Snippets
  • Includes
  • Inheritance
  • Using Extensions
  • Recursive Navigations
  • Working with Images
  • Multilingual Content