Forum Discussion

tagged-leo's avatar
14 years ago

Retrieve Title Name from Ancestor

I have a custom component that utilizes the page title (using coreNode.title) to display different content.  For example, when I navigate to the Blogs section, I use:   <#if coreNode.title == "Blog...
  • AdamN's avatar
    14 years ago

    Hi tagged-leo,

     

    coreNode.ancestors provides a sequence of nodes representing the ancestors of the current node. So to get at the attributes for these ancestor nodes, you'll need to use the square brackets to index the sequence. For example:

     

    coreNode.ancestors[0].title

     

    You can also iterate through all of the ancestors using the list directive in freemarker,for example:

     

    <#list coreNode.ancestors as ancestor> ...</#list>

     

    One other suggestion, you may want to use id instead of title when attempting to identify certain nodes as part of the logic. The value of title is always what's configured in the admin for that node, so if someone where to change the title of the node, then the component may not behave as expected. If you use id, on the other hand, that value will always stay the same for the node.

     

    I hope this helps!