[Radiant] Parent tag?

John W. Long ng at johnwlong.com
Wed Aug 2 14:07:06 CDT 2006


Andrew Hodgkinson wrote:
> It needs this tweak:
> 
>   define_tag 'parent' do |tag|
>     tag.locals.page = page.parent || page
>     tag.expand
>   end
> 
> Note the "|| page" on the second line.

Instead of taking the approach above, let's do this:

   define_tag 'parent' do |tag|
     parent = tag.locals.page.parent
     tag.locals.page = parent
     tag.expand unless parent.nil?
   end

This way the tag will not be rendered if the parent doesn't exist. The 
above also makes the tag context sensitive (so you can use it inside a 
children:each tag).

We should also add the if_parent and unless_parent tags:

   define_tag 'if_parent' do |tag|
     tag.expand unless tag.locals.page.parent.nil?
   end

   define_tag 'unless_parent' do |tag|
     tag.expand if tag.locals.parent.nil?
   end

If someone can get me a unit tested patch for this I'll apply it.

--
John Long
http://wiseheartdesign.com



More information about the Radiant mailing list