17488 Posts in 4473 Topics by 1978 members
|Go to End|
20 November 2008 at 9:22am
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.
20 November 2008 at 2:29pm
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.
Also be sure to checkout the built in page controls if you haven't already.
20 November 2008 at 7:57pm
Yeah normally $URLSegment works well for doing different styles for different pages provided that you dont need to change the URL too often
|Go to Top|