Jump to:

3431 Posts in 1025 Topics by 864 members

Template Questions

SilverStripe Forums » Template Questions » Using "IF" block to call specific CSS

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

Page: 1
Go to End
Author Topic: 1154 Views
  • clschnei
    Avatar
    Community Member
    2 Posts

    Using "IF" block to call specific CSS Link to this post

    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 %>

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Using "IF" block to call specific CSS Link to this post

    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.

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