New ways to use Snippets

Posted by Jim Gay on Wednesday, August 13, 2008 | |

As of version 0.6.8, Radiant includes the ability to wrap a block of content with snippets.

Andrew Neil wrote the wrappits extension which adds this ability to Radiant instances of earlier versions. Version 0.6.8 rolled this into the core.

Michael Klett wrote the nested_layouts extension which provides similar functionality but does it with layouts.

Here’s some documentation about how you can use the new features in Snippets, straight from the horse’s mouth. The content below refers to the extension, but it’s all a part of the core now:

Wrappits are an enhanced version of Radiant’s native Snippets. This extension enables you to call a snippet as a double

    <r:snippet name="wrapper">
      Content between opening and closing tags

The "Content between opening and closing tags" can be inserted anywhere within the "wrapper" snippet itself by calling
the tag ‘<r:yield/>’.

For example, the following could be saved in a Snippet called "rounded-corners":

    <div class="top-left rounded">
      <div class="top-right rounded">
        <div class="bottom-left rounded">
          <div class="bottom-right rounded">

The snippet above could then be called, from any Page or Layout, as follows:

    <r:snippet name="rounded-corners">
      This lorem ipsum has rounded corners, dolor sit amet...

In this example, the ‘<r:snippet>’ opening tag would correspond to the four opening div tags, and the ‘</r:snippet>’
closing tag would correspond to the four closing div tags.