Yet another trick for Radiant CMS: Reusable snippets
In my endless quest to get DRY with Radiant, the Rails-based CMS for the new Pathfinder website, I made another exciting discovery last week: Snippets are basically just server-side includes that get interpolated into your pages before Radiant's custom tags are parsed. This means that you can create a snippet to, say, display a bunch of information about a page and then plug that snippet into any number of different contexts.
Consider the following three examples, all of which assume you've created a snippet called "whatever" that displays a few named page parts and the publish-date of a specific page within Radiant:
- Here, our snippet is executed for each child of the current page. The result for each page appears within a paragraph.
<r:children:each> <p> <r:snippet name="whatever"/> </p></r:children each>
- Here, our snippet is executed for each child of the current page and, if they exist, each grandchild. The display this time is as a series of nested unordered lists.
<r:children:each> <div> <r:if_children> <ul> <r:children:each> <li> <r:snippet name="whatever"/> </li> </r:children:each> </ul> </r:if_children> </div></r:children:each>
- Here, our snippet is executed for each child of a specific page within the site and the display is driven by a block-quotation wrapper.
<r:find url="/whatever/"> <r:children:each> <blockquote> <r:snippet name="whatever"/> </blockquote> </r:children:each></r:find>
The upshot is that as long as the code that calls a snippet provides that snippet with an appropriate context, the snippet will execute as expected. This allows for a lot of smart, DRY patterns in your system of layouts, pages and snippets. Depending on whether it lives in an unordered list, a div, a paragraph or a blockquote, you can even style your snippet differently using CSS. The use of specific CSS classes would provide even more fine-grained control.
The new, Radiant-backed Pathfinder website is just days away from launching. We look forward to sharing it with you.
Topics: Radiant CMS
Leave a comment
About Pathfinder
Follow the Blog
-
Get a monthly update on best practices for delivering successful software.
Subscribe via email
Subscribe via RSS
Categories
Topics
Archives
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
Blogroll
Recent
- Elements of Testing Style
- Aesthetics and Web Design
- Asterisk-Java Testing with Groovy
- 3 Misuses of Code Comments
- Fluently NHibernate
- Digging a Hole and Covering it with Leaves — The Software Development Version
- The Importance of User Experience - Do You Understand It in Your Bones?
- Writing Your Own Protocol With NSURLProtocol
- What’s In Your Dock: iPhone edition
- Feature Fatigue
