Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Can If Statements do this?


Go to End


3 Posts   834 Views

Avatar
Johan

Community Member, 49 Posts

4 December 2011 at 1:51am

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.

Avatar
stallain

Community Member, 68 Posts

4 December 2011 at 1:38pm

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

Avatar
Nivanka

Community Member, 400 Posts

4 December 2011 at 3:46pm

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.