Forum

Thread tagged as: Question

Passing value into title of perch_layout

I'm working with a 2 page list/detail setup. On the detail page, I want to be able to pass the value of the id "name" from my template: <perch:content id="name" type="text" label="Name" size="xl" required="true" title="true" /> into the title of perch_layout.

In the docs, I found this (on how to do this with blog),

<?php
$title = perch_blog_post_field(perch_get('s'), 'postTitle', true);
perch_layout('global.header', array(
  'title'=>$title
));
?>

What would be the syntax to grab the value of a field for a regular perch content region like mine?

Franz Neumann

Franz Neumann 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd need to get the value using perch_content_custom() - either by using skip-template or by creating a template that includes just the information you want.

You can have it return the value to a variable by passing true as the third argument.

I'm afraid I'm stumped. I've spent the past couple hours trying, but I'm obviously missing something. I've searched for help in the docs, forum and by googling via site:www.grabaperch.com/forums/ but I can't manage to get this to work. I created a template with just the information I want to display for the page_layout title variable, as below. But I'm clearly doing something wrong. The page simply outputs the value at the top of the page and not in the <title> tag.

<?php $title = perch_content_custom('Team', array( 'page' => '/who-we-are/index.php', 'template' => 'team_detail_name.html', 'filter' => 'slug', 'match' => 'eq', 'value' => perch_get('s'), 'count' => 1, )); ?>

<?php perch_layout('header', array( 'title'=> $title, 'class'=>'whoweare', )); ?>

Thanks.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can have it return the value to a variable by passing true as the third argument.

$title = perch_content_custom('Team', array( 
    'page' => '/who-we-are/index.php', 
    'template' => 'team_detail_name.html', 
    'filter' => 'slug', 
    'match' => 'eq', 
    'value' => perch_get('s'), 
    'count' => 1, 
), true);

Brilliant. Many thanks.