Forum Discussion

Lindsey's avatar
Lindsey
Leader
5 years ago

page.content.head.setTitle not working for custom page

The freemarker function .setTitle() is not working for me for a custom page that I created. I created a custom search page titled "forums". I tried following the instructions from this post to set the title tag for this page.

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?

  • Lindsey, This will only work when you have same type of text-key available in text-editor. Without adding text-keys, you cannot set title using context-object page.content.head.setTitle.

    Lets suppose in below code when you split "selectedLabels" and there will be two labels with label names "label1" and "label2".

    <#assign labelListParam = webuisupport.path.rawParameters.name.get("forum","")>
    	<#assign selectedLabels = labelListParam?split(",")/>

     

    So for "forums" cutom page your text-key for the title will be:

    page.forums.label1.title = The Title of the page with name label1

    page.forums.label2.title = The Title of the page with name label2

     

    • Lindsey's avatar
      Lindsey
      Leader

      Parshant could you just do page.forums.title = {0} for the text property, and add the labelsPageTitle variable as the parameter in the text property value?
      So it'd be 

      ${page.content.head.setTitle(text.format("page.forums.title", labelsPageTitle)}

      • Lindsey's avatar
        Lindsey
        Leader

        Parshant I tried it as mentioned in my previous comment, and it does not work. Is there not a way to have variables in the title tag text property?