× Warning! This forum is in archival status. New contributions may not work.
language selection revisited
  • I am trying a slightly more advanced language selection option now:

    I'm trying to test some different cases for displaying language options for only those translations that exist, where not every article or issue is in every language, such that an article may return a blank 404 or a front page or issue may come back empty.

    Here's what I thought should work:
    {{ if($gimme->template->name == "article.tpl") }}
          {{ list_languages of_article="true" }}
    {{ else }}
          {{ list_languages of_issue="true" }}
    {{ /if }}
          <li><a {{ if ($gimme->language->code == $gimme->default_language->code) }}class="selected"{{ /if }} href="{{ url }}">{{ $gimme->language->name }}</a>

    However, while the <li>...</li> piece works well, the {{ if }}... {{ /if }} section of code causes the page to load blank with nothing other than <body> and <div id="container">.

  • 4 Comments sorted by
  • Hi,

    maybe you can try with this option available for article object: translated_to(<language_code>)

    So for example you can check {{ if $gimme->article->translated_to(es) }}<li>Spanish</li>{{ /if }}

    General language switcher is usually built this way:

    {{ list_languages of_publication="true" }}
                <li{{ if $gimme->language == $gimme->default_language }} class="current"{{ /if }}><a href="{{ url }}">{{ $gimme->language->name }}</a></li>
              {{ /list_languages }}

    If you try to jump to, say, Spanish when on article which is not translated to spanish, url context will fall back to spanish issue, thus you won't get 404 page but issue page will be shown. 
    Ljuba Rankovic
    Senior Front End Developer, Sourcefabric

  • Thanks,
    I'll give that a shot.

    Is there a comprehensive list of all the $gimme command options? Looking through the manual for language references had me bouncing around between sections and i couldn't help but think I was probably missing options.
  • also, that's a bit better for the "selected" ("current") check. It was not behaving when I had the full $gimme->default_language->code in the <li> tag, so putting it into <a> was just a workaround.
  • also again,
    I had that same language option code, minus the if statement for determining 'current'/'selected' and I definitely get sent to / Home / error page and see "Sorry, the requested page was not found."