- We design and build extraordinary applications for companies looking to make the next great idea a reality.
- learn more
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
Recent
- Bandwidth profiling Flex projects and more with Charles
- iPhone SDK: UIViewController Testing & TDD
- Icons are evil; so are menus - unless you do them right
- The Truth About Designing For Security
- GWT, Gadgets and OpenSocial, Part 2
- Has Many has_many: A Refactoring Story
- The Hidden Power of Canvas
- Review of fixture_replacement2 plugin
- Chess Game Viewer in GWT
- From JSP to Ruby on Rails: First thoughts on front-end coding conventions
Archives
- 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

