public
Description: Allows you to create double tag snippets (<r:snippet></r:snippet>), whose content can be inserted in the snippet with <r:yield/>.
Homepage:
Clone URL: git://github.com/nelstrom/radiant-wrappits-extension.git
nelstrom (author)
Tue Jul 29 15:20:18 -0700 2008
commit  7327e7025cb7e6bea77147bbacf1be1be87a0a12
tree    1914ce7b58c753d9798005f7646dfa294004ccd1
parent  0f42730156b81ba6b3200b733e0aa2696daceb37
100644 49 lines (33 sloc) 2.039 kb

Wrappits

This extension was rolled into the Radiant core for version 0.6.8.

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

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

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">
        <r:yeild/>
      </div>
    </div>
  </div>
</div>

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...
</r:snippet>

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.

If you are familiar with Ruby, you may find a resemblance between the pattern used above and Ruby's blocks. A similar approach to this is advocated in designing helpers and partials in Rails with a block.

A few points to note:

  • you can still call snippets as a single tag
  • the <r:yield/> tag will output nothing if called from a single tag, or from an empty double-tag
  • you can use <r:yield/> as many times as you like within a snippet. In each case, it will output the contents of the calling snippet tags.

By installing this extension, you should not see any change in the behaviour of existing snippets in your Radiant project.

Installation

Just copy this extension to the /vendor/extensions directory of your Radiant project, and restart your server.

You don't need to run any rake tasks.