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.

  • 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

      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

      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

        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.