Check for children

In my base template, I want to output a

only if some children
of the current page exist. How can I check for children of a page?

Steven N. http://outerthought.org/
Outerthought Open Source Java & XML
stevenn at outerthought.org stevenn at apache.org

On 24/09/06, Steven N. [email protected] wrote:

In my base template, I want to output a

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:

This is explained in more details on the wiki - to which I hope you’ll
contribute your experiences with! :slight_smile:

http://dev.radiantcms.org/radiant/wiki/HowToDefineGlobalTags


Regards,
Dave

Dave C. wrote:

  • Perhaps, but the children:each tag will only work if children exist. So
    in a sense it encapsulates the if_children idea. If you give us a
    little more context or detail, I might be able to come up with some code
    that will do the trick.

    Sean C.
    seancribbs.com

    On 24 Sep 2006, at 18:49, Sean C. wrote:

    exist. So in a sense it encapsulates the if_children idea. If you
    give us a little more context or detail, I might be able to come up
    with some code that will do the trick.

    I have a

    containing a secondary navigation that should only be
    inserted when there’s underlying children.

    Something like:

    <r:if_children>

    More information

    would do the trick.

    Steven N. http://outerthought.org/
    Outerthought Open Source Java & XML
    stevenn at outerthought.org stevenn at apache.org

    On 24 Sep 2006, at 17:50, Dave C. wrote:

    </r:children:each>

    This is explained in more details on the wiki - to which I hope you’ll
    contribute your experiences with! :slight_smile:

    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 N. http://outerthought.org/
    Outerthought Open Source Java & XML
    stevenn at outerthought.org stevenn at apache.org

    On 24 Sep 2006, at 22:24, Dave C. wrote:

    If you could provide it as a plugin, that would be awesome! :slight_smile:

    Creating a plugin for a two-line patch for a totally trivial addition
    would be overkill, no?

    Index: app/models/page_context.rb

    — app/models/page_context.rb (revision 122)
    +++ app/models/page_context.rb (working copy)
    @@ -40,6 +40,15 @@
    end

      #
    
    • <r:if_children>…</r:if_children>

    • Checks for existing children.

    • define_tag ‘if_children’ do |tag|
    •  tag.expand if tag.locals.page.has_children?
      
    • end
    • <r:children:count />

      Renders the total number of children.

    Steven N. http://outerthought.org/
    Outerthought Open Source Java & XML
    stevenn at outerthought.org stevenn at apache.org

    On 25/09/06, Steven N. [email protected] wrote:

    On 24 Sep 2006, at 22:24, Dave C. wrote:

    If you could provide it as a plugin, that would be awesome! :slight_smile:

    Creating a plugin for a two-line patch for a totally trivial addition
    would be overkill, no?

    Sure, I’m just thinking of people who didn’t install with --unpack
    that’s all :slight_smile:


    Regards,
    Dave

    On 24/09/06, Steven N. [email protected] wrote:

    en that indeed did the trick.

    :slight_smile:

    No idea however if this is the best way
    to do this.

    This is exactely the way I have done it.

    I can provide a (obviously) very simple patch if people
    are interested.

    If you could provide it as a plugin, that would be awesome! :slight_smile:


    Regards,
    Dave

    Actually, there are a score of “global tags” that I’m thinking of
    collecting
    and putting into a patch, although most people could put them in a
    plugin in
    the meantime like I demonstrated in the How To.

    Sean C.
    seancribbs.com

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs