Thanks for your answer. However, parse doesn't work quite as I hoped. Calling parse will parse the given string immediately in the current context and return a string. I need to postpone the actual parsing until the context is changed to each item in the collection. I was hoping to be able to construct some kind of proxy-object that would respond to #call just like when nested templates has been given.

I can easily solve this by just inserting the default value unparsed, and then have a helper method that checks if the value is a string to parsed or a method to be invoked, but I find that solution quite ugly. I'm obsessing about it, because I'd like to contribute the tag to the Radiant core, so I want it to coded right.


On 01/06/2008, at 16:51, Sean Cribbs wrote:


Call parse, passing the text you want to parse:

hash[:normal] ||= parse('<li><r:link /></li>')


Casper Fabricius wrote:
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:

- and the tag uses this nested tag by doing:
   hash = tag.locals.collection_tag = {}

- and then later:

- 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]   ||= {'<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?

Casper Fabricius

Radiant mailing list

Radiant mailing list

Radiant mailing list

Reply via email to