Forum Discussion

Lindsey's avatar
Lindsey
Leader
6 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?

5 Replies

  • 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
    6 years ago

    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
    6 years ago

    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?

  • Parshant's avatar
    Parshant
    Boss
    6 years ago

    Hi Lindsey ,

    In khoros ".title" text-keys, we can change the keys name dynamically while passing to text-format keys, but can't change its value with dynamic parameters.

    This can only work like this:

     

    <#assign dynamicLabel = "testpage" />

     

    text.format("page.forums. " + dynamicLabel+ ".title")

    Your text-key need to be like below.

     

    page.forums.testpage.title = Title of the Test Page

     

     

  • Lindsey's avatar
    Lindsey
    Leader
    6 years ago

    Parshant That's not going to work for what I need, since I need to add the label name to the title tag, and the label could be anything. So I guess I cannot use setTitle() for the page. I could use javascript to set document.title, but we'd really like the title to be set without javascript so Google can read the tag