Forum Discussion

Lindsey's avatar
Lindsey
Leader
6 years ago

Custom page title with variable

We created a custom labels search page on our community. I want the page title and browser tab to vary with the label the user is searching, like if they search "Foo" label, then I want the browser tab to show Foo Labels. Basically, I want our page title to be {0} Labels. 

Is there a way to pass parameters into the page title like that?

  • Lindsey,

    Yes you are correct we cannot change Custom Page titles Dynamically with freemarker and text-keys.

    But if its just for display purposes you can use javascript code in custom component and include to the custom page to change with Dynamic values.

    <#assign Pagetitle = coreNode.title />
    <script>
     document.title = "${Pagetitle}";
    </script>

     I know this method is not good but, its the only solution I have.

7 Replies

  • Lindsey,

    You custom page title key will be something like this:

    page.custom_page_name.title = Page Title

     

    So your value should be similar to

    page.custom_page_name.title = {0} Labels

     

    and your dynamic value will be passed using:

    page.custom_page_name.title = {0} Labels
    <#assign Pagetitle = text.format("page.custom_page_name.title",value1) />

     

     

  • Lindsey's avatar
    Lindsey
    Leader
    6 years ago

    This did not work. Now the browser tab just appears as {0} labels. I do have the logic for which labels are selected in an endpoint though, so maybe that is why it is not working

  • Lindsey's avatar
    Lindsey
    Leader
    6 years ago

    Parshant I tried putting this logic into the component that exists on the page and just added "test" as the parameter, and this still didn't work. How would the page be able to know to take from the variable "Pagetitle" and put it in the title tag of the head tag?

  • Parshant's avatar
    Parshant
    Boss
    6 years ago

    Lindsey,

    Yes you are correct we cannot change Custom Page titles Dynamically with freemarker and text-keys.

    But if its just for display purposes you can use javascript code in custom component and include to the custom page to change with Dynamic values.

    <#assign Pagetitle = coreNode.title />
    <script>
     document.title = "${Pagetitle}";
    </script>

     I know this method is not good but, its the only solution I have.

  • Lindsey's avatar
    Lindsey
    Leader
    6 years ago

    Parshant that could work. So I am trying to put a hidden div that has the items I want to go into the head title, then in the liaAddScript I am doing document.getElementById to get that hidden div content. Then I do document.title = the freemarker text variable. It looks like this:

    const headTitle = document.getElementById("headTitle");
    document.title = "${text.format("page.GlobalLabels.title", )}";

    Do you know how I can get that headTitle javascript variable into the freemarker variable? Is that possible? 

  • Parshant's avatar
    Parshant
    Boss
    6 years ago

    Lindsey,

    You can simply do that with assigning value in freemarker variable for label name and then use it in javascript as mentioned in my above comments.

    <#assign Pagetitle = label_title + "Label" />
    <script>
     document.title = "${Pagetitle}";
    </script>