Jump to:

23476 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Can If Statements do this?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 459 Views
  • Johan
    Avatar
    Community Member
    49 Posts

    Can If Statements do this? Link to this post

    Hi all

    In the SS files I want to change the content of the SS file dependent on the language, so for German I want to show "de"... and I know $Level(2).URLSegment also outputs de from the URL. But when put into an IF it is not working...

    <% if $Level(2).URLSegment = de %>
       <p>de
    <% else %>
       <p>world
    <% end_if %>

    Hope some one can help.

    Thank you.

  • stallain
    Avatar
    Community Member
    61 Posts

    Re: Can If Statements do this? Link to this post

    Hi, you can maybe try something like :

    <% control Level(2) %>
    <% if URLSegment = de %>
    <p>...</p>
    <% else %>
    <p>...</p>
    <% end_if %>
    <% end_control %>

    But I think that to change the content depending on the language, there's something simpler :

    <% if Locale = de_DE %>
    ...
    <% end_if %>

    Stan

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Can If Statements do this? Link to this post

    This code is wrong,

    <% if $Level(2).URLSegment = de %>

    you have to drop the $ there, when you are using variables in IF blocks drop the '$'

    also I agree with @stallain here, $Level(2) is a ComponentSet so you have to iterate through that.

    459 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.