21
Dec
1
Select a theme using a URL parameter
When I develop SilverStripe sites, I usually get functionality working in the default theme blackcandy before getting it working in the final templates. This way, authors can start adding content and seeing how it looks on the page, and I can get early feedback about the functionality. Also, as a developer I get to see real content in the browser early in the process. So does the designer.
I'm sure this process is nothing new - and I realise form-first vs function-first is an old debate - but one thing I wanted to share is some code my team and the client found useful in a recent project.
I added the ability to select a theme based on a parameter in the URL, either for the current page request or for session. This meant we were able to throw around URLs specifying the theme, choosing a theme depending on whether we were discussing the (visual) design or the functionality and content.
http://www.mywebsite.com/myurlsegment/?theme=blackcandy
sets the theme for a single request.
http://www.mywebsite.com/myurlsegment/?setTheme=blackcandy
sets the theme for the session.
Early in the client project, I made sure all the functionality and content worked in both themes, but as more pages worked in the real theme, we left blackcandy behind.
Having said that, I kept the most involved pages working in blackcandy right until the end, so we could always view the new content, such as a large image due to be displayed in a lightbox, or content due to be included in a slider effect was implemented. That way, we kept the feedback coming: by the time the lightbox effect worked, we already knew the image was getting all the way from author to browser, appropriately downsampled and compressed, and everyone was already happy with the size and quality of the large image.
Here's the essence of code, suitably unrefactored for your viewing pleasure.
See also Martijn van Nieuwenhoven's SSbits snippet:
http://www.ssbits.com/create-a-front-end-theme-switcher/
About the Author
Name: Toby Champion
Website: http://www.tobychampion.co.uk/
Agile SilverStripe developer near Seattle, USA, originally from Brighton, England.Comments (1)
-
That's great, thanks.
I wondered how they implemented that on Silverstripe and why it isn't part of the core functionality.
Works a treat.Posted by Spencer, 14/02/2010 2:02am (24 days ago)
RSS feed for comments on this page RSS feed for all comments