Forum
How do I pass the page title into a template in Runway?
Hi! I'm trying to pass the Perch-admin created Page Title into a content template (specifically into a hidden field in a global form, necessary for submission tracking) in Perch Runway.
I've spent hours trying to figure this out and tried handfuls of solutions unsuccessfully.
I want to do this in an HTML template, not in a PHP file, as there's a ton of HTML around this one hidden field and I don't want to echo it all.
My last attempt involved set_var and perch_content_create...
At the top of my header.php:
<?php
PerchSystem::set_var('trc_title', perch_pages_title(true));
perch_content_create('Contact Form', array(
'template'=>'contact-form.html'
));
?>
...and then in the content template "contact-form.html":
<input id="Field7" name="Field7" type="text" class="middle hide" value="<perch:content id="trc_title" hidden="true" />">
<!-- (more form code followed by this test) -->
<p><perch:content id="trc_title" hidden="true" /></p>
The form displays, but I'm not getting the page title in either the the input or the paragraph. What am I doing wrong?
Joel, at the end of contact_form.html add
<perch:showall />
and see if the debug output has thetrc_title
variableI added
<perch:showall />
to the template but the debug output does not showtrc_title
.Along the way I noticed that my perch:content call was wrong. I should have
type="hidden"
instead ofhidden="true"
:That did not solve the problem. I also tried declaring the variable in the header.php file:
...but that produces no joy either.
Huh, I think I figured it out. In the page template ("home.php") I was declaring:
but in an older support thread I saw a suggestion that it needed to be:
This seems to work, although I am confused, because I also have an item I want to be editable
<perch:content id="form_mailto" label="Send Message To" />
in the same content template ("contact-form.html"). I thought that using perch_content_custom meant I would not be able to edit that field in Perch admin. That appears to be not the case.perch_content_custom
is parsed at runtime, which is what you need if you want to pass something in.It does not create a region, so you will need to use
perch_content
orperch_content_create
to create the region, otherwise it behaves in the same way but the output is not cached at edit time.