[Radiant] check for children

Steven Noels stevenn at outerthought.org
Sun Sep 24 14:35:54 CDT 2006


On 24 Sep 2006, at 17:50, Dave Crossland wrote:

> On 24/09/06, Steven Noels <stevenn at outerthought.org> wrote:
>> In my base template, I want to output a <div> only if some children
>> of the current page exist. How can I check for children of a page?
>
> You need to define a new tag like <r:if_children> that would work  
> like this:
>
> <ul>
>   <r:children:each by="title" order="asc">
>   <li><r:link /></li>
>   </r:children:each>
> </ul>
> </r:if_children>
>
> This is explained in more details on the wiki - to which I hope you'll
> contribute your experiences with! :-)

I added this to my --unpack'ed version of app/models/page_context.rb :

     #
     # <r:if_children>...</r:if_children>
     #
     #
     define_tag 'if_children' do |tag|
       tag.expand if tag.locals.page.has_children?
     end

en that indeed did the trick. No idea however if this is the best way  
to do this. I can provide a (obviously) very simple patch if people  
are interested.

</Steven>
-- 
Steven Noels                            http://outerthought.org/
Outerthought                              Open Source Java & XML
stevenn at outerthought.org                stevenn at apache.org





More information about the Radiant mailing list