Forum Discussion

davidtwamley's avatar
15 years ago

Page Title from FreeMarker

I've seen how to retrieve page.name in FreeMarker. It returns a value like "BlogPage" which is really more of a template name. Is there a way to get at the actual title of the page (the value that gets echoed in the <h1> tag)? This would provide a useful avenue for branching logic.

  • Hi, David.

     

    There is, but it depends on the page. For example, if you're on a board/blog/idea page, a category page or the community homepage, you can use coreNode.title to get the name. If you're on a message, however, you'll need to use page.context.thread.topicMessage.subject.

     

    Hope that helps!

6 Replies

  • AdamT's avatar
    AdamT
    Lithium Alumni (Retired)
    15 years ago

    Hi, David.

     

    There is, but it depends on the page. For example, if you're on a board/blog/idea page, a category page or the community homepage, you can use coreNode.title to get the name. If you're on a message, however, you'll need to use page.context.thread.topicMessage.subject.

     

    Hope that helps!

  • Very nice! This provides another way to treat specific pages special:

     

    <#if coreNode.title == "My Page Title">
    ...content just for this page goes here...
    </#if>
  • This is the best way to get the page title:

     

    <#assign pageTitle = (page.content.head.title)! />

     

     Then you can create a function to strip out the appended "- Community name" if need be

  • ChiaraS's avatar
    ChiaraS
    Lithium Alumni (Retired)
    8 years ago

    Another option is to take the last part of the breadcrumb:

    <#assign crumb = page.content.nav.breadcrumb.crumbs?last />
    <#assign pageTitle = crumb.text />