perch_pages_title in a HTML template

  • Hi

    I've created a variable using perch_pages_title, using this code:

    1. $page_title = perch_pages_title(true);
    2. PerchSystem::set_var('page_title',$page_title);

    I can test the variable is working with echo $page_title;

    I was hoping to add the page_title variable to a HTML template, like this:

    1. <perch:content id="page_title" type="text">

    But it doesn't work? A new text field appears in the CMS, pressing save does nothing.

    1. <perch:content id="page_title" type="hidden">

    Replacing type="text" with type="hidden" hides it from the CMS template.

    perch:showall shows perch_namespace, is perch:content but the id="page_title" variable isn't getting picked up?

    Using Latest Perch Runway (3.1.4)

    Any ideas?

  • As said above, if you want to pass a variable into the template you need it to be processed at runtime with perch_content_custom()...

    But in this case, would <perch:content id="_page" type="hidden"> be useful to you?

    It outputs the page itself which you could relate to the title someway?

    If it's essential to have the variable available to your template and you don't want to process the template at runtime this might be a way to solve it... or at least work round.

  • Hi hus_hmd

    Ah, of course! Friday afternoon brain failure. Thanks, it works now.

    Anyone needing to do this just do this:

    1. //Create a variable
    2. $page_title = perch_pages_title(true);
    3. PerchSystem::set_var('page_title',$page_title);

    Add this to your HTML page template

    1. <perch:content id="page_title" type="hidden">

    Make sure you're using perch_content_custom to render the template

    1. perch_content_custom('Your region name');