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.

Template Questions /

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

Using "IF" block to call specific CSS


Go to End


2 Posts   1850 Views

Avatar
clschnei

Community Member, 2 Posts

28 January 2010 at 1:54pm

Edited: 28/01/2010 1:54pm

I have this in my main Page.ss, but I want to switch background depending on the layout using an if statement. Is this correct syntax? If not, what am I missing/doing wrong?

<% if $Layout = HomePage %>
<link href="/themes/ofarm/css/homepage.css" rel="stylesheet" type="text/css" />
<% else %>
<link href="/themes/ofarm/css/page.css" rel="stylesheet" type="text/css" />
<% end if %>

Avatar
Willr

Forum Moderator, 5523 Posts

28 January 2010 at 5:44pm

Couple notes - you don't need to use a $ when your inside the <% %> tags and $Layout can't be used for that sadly. You have to use ClassName or you can use URLSegment

<% if URLSegment = home %> or <% if ClassName = HomePage %> if you have made a custom HomePage class which you can use.