Forum Discussion

Lindsey's avatar
Lindsey
Leader
6 years ago

page.content.head.setTitle not working

For SEO purposes, we are trying to change the page title and description on the ForumTopicPage so the tags in the head tag will look similar to how they did in our old forums site.
I found this article about how to change the page title and description. In Common.init.ftl, I added this:

<#if page.name == "ForumTopicPage">
${page.content.head.setTitle(page.context.thread.topicMessage.subject + " - " + page.context.thread.topicMessage.board)}
${page.content.head.setDescription(page.context.thread.topicMessage.subject)}
</#if>

This did not work - the content in the title and description tag did not change. I also tried just adding this:

${page.content.head.setTitle("Test")}
${page.content.head.setDescription("Test")}

This did not work either - I expected every page to have their title and description meta tag to contain "Test", but they remained the same. How do I properly use setTitle and setDescription functions to change the title and meta description tags on the ForumTopicPage?

6 Replies

  • Lindsey,

    You can use page.content.head.setTitle and page.content.head.setDescription context object only for Custom Pages. It will not work for other pages or mapped custom pages.

     

  • Lindsey's avatar
    Lindsey
    Leader
    6 years ago

    Parshant  Oh shoot. Is there any other way to set the ForumTopicPage head title and meta description without using Javascript and use freemarker context objects as a variable in it?

  • Lindsey's avatar
    Lindsey
    Leader
    6 years ago

    I instead could set it in the page.head.title@page:ForumTopicPage text property, however I'm not sure how to get the board related to the current page here. Is there a text property that contains the current board I could add as a variable to this text property?

  • TrippB's avatar
    TrippB
    Khoros Alumni (Retired)
    6 years ago

    Lindsey , I don't think there's anyway to get node specific info in text properties. You can only use custom page quilts to make "node" specific text keys. You can't use dynamic data in the key files.

  • Lindsey's avatar
    Lindsey
    Leader
    6 years ago

    setTitle also is not working for me for a custom page that I created. I created a custom search page titled "forums". In Common.init.ftl, I have this code: 

    <#if page.name == "forums">
    	<#assign labelListParam = webuisupport.path.rawParameters.name.get("forum","")>
    	<#assign selectedLabels = labelListParam?split(",")/>
    	<#assign labelsPageTitle = ""/>
    	<#assign titleIsEmpty = true/>
    
    	<#if selectedLabels?has_content>
    		<#list selectedLabels as selectedLabel>
    			<#if selectedLabel?contains("_")>
    				<#if !titleIsEmpty>
    					<#assign labelsPageTitle += ", "/>
    				</#if>
    				<#assign labelsPageTitle += selectedLabel?keep_after("_")/>
    				<#assign titleIsEmpty = false/>
    			<#else>
    				<#if !titleIsEmpty>
    					<#assign labelsPageTitle += ", "/>
    				</#if>
    				<#assign labelsPageTitle += selectedLabel/>
    				<#assign titleIsEmpty = false/>
    			</#if>
    		</#list>
    		${page.content.head.setTitle(labelsPageTitle)}
    	<#else>
    		${page.content.head.setTitle("Labels")}
    	</#if>
    </#if>

    The page title for this page is just showing up as "forums | (our community name)". Why is this not working for me even though it is for a custom page?