Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Contextual Body Ids

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1249 Views
  • chrisjlee
    Avatar
    Community Member
    5 Posts

    Contextual Body Ids Link to this post

    I'm actually an avid Wordpress hack (very new to silverstripe and liking a lot of it) and my favorite thing was being able to change layouts/columns on the fly with primarily css. In order to do that I would require the body tag to adapt different Id's and classes attached. I've tried doing a forum search; but nothing that satiates my quest for an answer.

    I had a discussion with a colleague about adapting and creating the same functionality in a template. We came up with some solutions but was thinking maybe there's a more elegant approach.

    1. Use the $title and place it where the body tag and have SS parse it there
    2. Use conditional level modifiers <% if level ( 0 ) % > to create different id's. Eventually it would output something like <body class="level-1">

    If anyone could offer a more elegant solution i'd love to document it in the wiki.

    Just a caveat: i'm i just started learning the ins and outs of Silverstripe. I apologize if there are any egregious statements. There are probably many ha.

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: Contextual Body Ids Link to this post

    Generally people use the $URLSegment variable in the body tag. It returns the url part after the domain name, i.e the url segment lol.

    This would be pretty much the same thing as using the $title in there, except it would probably be shorter and no spaces, only dashes. About Us = about-us

    That's probably the best way to do it via CSS. You can assign specific templates for certain page types by creating new page types. Also, the $Layout variable works for good chunks of good.

    Hammish just wrote up a good explanation for a new user which further elobrates on the docs.

    http://www.silverstripe.com/site-builders-forum/flat/231937#post231943

    Also be sure to checkout the built in page controls if you haven't already.
    http://doc.silverstripe.com/doku.php?id=built-in-page-controls

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Contextual Body Ids Link to this post

    Yeah normally $URLSegment works well for doing different styles for different pages provided that you dont need to change the URL too often

    <body id="$URLSegment">

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