Forum

Thread tagged as: Question, Problem, Runway

Title in the header layout - list / detail page

I have my title field in my header layout

<title><?php perch_layout_var('title'); ?></title>

Then in my list / detail page I am looking to output the page title but its not working this is what I have tried


$title = if (perch_get('s')) { perch_content_custom('First Team', array( 'template' => 'squad/first_team_title.html', 'filter' => 'slug', 'match' => 'eq', 'value' => perch_get('s'), 'count' => 1, 'skip-template' => 'true', } else { echo "First Team"; } )); perch_layout('global/header', [ 'title'=> $title ]);

This is not right, any help would be great

Barry

Fishtank Creative

Fishtank Creative 2 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

if (perch_get('s')) {
        $title = perch_content_custom('First Team', array(
        'template'      => 'squad/first_team_title.html',
        'filter'        => 'slug',
        'match'         => 'eq',
        'value'         => perch_get('s'),
        'count'         => 1,
        'skip-template' => 'true',
        ));

} else {
            $title =  "First Team";
}


    perch_layout('global/header', [
        'title'=> $title
    ]);
Drew McLellan

Drew McLellan 2638 points
Perch Support

The only thing this flags is that in the first cast $title will be an array, and the second a string. So watch out for that.

I'm not sure how to get around this. The list page now works as expected but the detail page is showing this error

<br />
<b>Warning</b>:  htmlspecialchars() expects parameter 1 to be string, array given in <b>/Users/Barry/Sites/wiganwarriors/admin/core/lib/PerchUtil.class.php</b> on line <b>159</b><br />
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which element from the array do you want?

I just want the Title from the template

<perch:content id="name" type="text" required="true" label="Full Name" title="true" />

So it outputs

<title>Title of the Detail Page</title>
Drew McLellan

Drew McLellan 2638 points
Perch Support

$team = perch_content_custom('First Team', array(
        'template'      => 'squad/first_team_title.html',
        'filter'        => 'slug',
        'match'         => 'eq',
        'value'         => perch_get('s'),
        'count'         => 1,
        'skip-template' => 'true',
        ));
$title = $team[0]['name'];

Thankyou that worked perfectly. Thanks

Here is the final code for anyone having the same question

<?php
    if (perch_get('s')) {
        $team = perch_content_custom('First Team', array(
            'template'      => 'squad/team_title.html',
            'filter'        => 'slug',
            'match'         => 'eq',
            'value'         => perch_get('s'),
            'count'         => 1,
            'skip-template' => 'true',
        ));
        $title = $team[0]['name'];
    } else {
        $title =  "First Team";
    }

    // Include the header. You can find this in tempates/layouts/global
    perch_layout('global/header', [
        'title'=> $title,
    ]);
?>