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 == "Blogs">

--->The show some custom content

</#if>

 

However, when I dig down to a specific blog, the page title changes and the ancestor.title field shows "Blogs."  How can I grab the ancestors.title so I can do the following:

 

</#if>

<#if coreNode.ancestor.title == "Blogs">

--->The show some custom content

</#if>

 

Unfortunately the system will not allow me to do this. 

 

Thanks.

  • 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!

     

  • AdamN's avatar
    AdamN
    Khoros Oracle

    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!

     

    • Adam looks like coreNode.ancestors[0].title worked like a charm.

       

      Thank you!