Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » Current Language in Template Conditional

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 3193 Views
  • svinkle
    Avatar
    Community Member
    16 Posts

    Current Language in Template Conditional Link to this post

    I've noticed in templates that I can use $Lang to output the current language. I'm trying to use this in a conditional statement such as:

    <% if "$Lang" == "en" %>
       $Content
    <& end_if %>


    I get the error:

    XML Parsing Error: not well-formed
    Line Number 137, Column 6:            <% if "en" == "en" %>
                ---------------------------------^

    Is there a correct way to check for this?

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Current Language in Template Conditional Link to this post

    Bad syntax....

    Drop the quotes and the $

  • svinkle
    Avatar
    Community Member
    16 Posts

    Re: Current Language in Template Conditional Link to this post

    I tried that as well. It produced a different kind of error.

    I was able to find a solution by using parts of the Multilingual Content recipe. I used two parts of step two. The first code block was used, I skipped the custom class "MultiLingual" entirely, and in the third block, I changed "$lang = MultiLingual::currentLang();" to "$lang = Translatable::current_lang();". The last step was to make sure my French custom field names ended in '_fr'.

    From what I've found in my research here, it seems like quite a hack job to try and have a multilingual web site when it comes to custom fields in classes. Unless, of course, I'm doing something terribly wrong.

  • CriaturaCreativaStudio
    Avatar
    Community Member
    73 Posts

    Re: Current Language in Template Conditional Link to this post

    Hello!

    Is there a way to display custom includes evaluating the current language?
    I find this very difficult to do, and since i'm not a programmer, all that i've tried was messing up the layout or giving me errors...

    If anyone can post here a way to evaluate the language inside the .ss files to include another, that would be great !

    Thanks in advance,

    Regards

    Eduardo

  • CriaturaCreativaStudio
    Avatar
    Community Member
    73 Posts

    Re: Current Language in Template Conditional Link to this post

    Any thoughts about this?

    Thanks in advance!

    Eduardo

  • ayyurek
    Avatar
    Community Member
    41 Posts

    Re: Current Language in Template Conditional Link to this post

    Hi,

    I am not a SS guru. Few weeks ago decided to build a site form my client with SS. I also needed this and with some try-and-see, found the solution.

    <% if Locale == en_US %>
    Here is the english text.
    <% end_if %>

    You can do this for other locales..

    3193 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.