[Radiant] Container tag with default values for nested tags
Casper Fabricius
me at casperfabricius.com
Sun Jun 1 04:26:49 CDT 2008
I'm developing a tag inspired by the way <r:navigation /> works; by
using nested tags to let the user specify how he wants to render a
given collection.
The user could write:
<r:collection_tag>
<r:normal><b><r:link></b></r:normal>
</r:collection_tag>
- and the tag uses this nested tag by doing:
hash = tag.locals.collection_tag = {}
tag.expand
- and then later:
hash[:normal].call
- to render the contents of the nested tag.
However, I want the user to also be able to write just:
<r:collection_tag />
- and the tag will populate hash[:normal] with a default value of,
say, <r:link />.
However, I don't know how to create a default value for a nested tag,
least not when it contains other Radius tags that need to be parsed in
the context of each iteration of the collection.
I have tried assigning default values with code such as:
hash[:normal] ||= '<li><r:link /></li>'
- or:
hash[:normal] ||= Proc.new {'<li><r:link /></li>'}
- but the first is just a string, and does not respond to the #call
method, and the second is just a proc, and do not in fact render
<r:link /> in the context, it just returns the string unparsed.
I know of several examples on using default values for tag attributes,
but not for nested tags. Any hints, ideas, examples?
Cheers,
Casper Fabricius
http://casperfabricius.com
More information about the Radiant
mailing list