John W. Long wrote:
> 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

I like that much better - a parent tag should never return self!  This 
makes it consistent with child behavior.

I'm in the process of moving but will submit something this week with 
tests unless beats me to it..

Jay
> 
> 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
> _______________________________________________
> Radiant mailing list
> [email protected]
> http://lists.radiantcms.org/mailman/listinfo/radiant

_______________________________________________
Radiant mailing list
[email protected]
http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to