Forum

Thread tagged as: Question

Show slug in Page Title - List & Detail page

I have a 2-page list and detail page as per this tutorial. https://solutions.grabaperch.com/architecture/two-page-list-and-detail

What code would I have to use to show the Detail page's main title (the Slug) in the Page Title?

Any helps is appreciated.

James Tedder

James Tedder 0 points

  • 6 years ago

James, add skip-template and return-html to perch_content_custom so you get both the defined fields in an array and the html response (rendered template).

Then you can do something like:

<?php include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php');

$element = perch_content_custom('Elements', [
    'page'          => '/listdetail/index.php',
    'template'      => 'listdetail/detail.html',
    'filter'        => 'slug',
    'match'         => 'eq',
    'value'         => perch_get('s'),
    'count'         => 1,
    'skip-template' => true,
    'return-html'   => true,
]);

$details = reset($element);
$content_html = $element['html'];

?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title><?php echo PerchUtil::html($details['title']); ?></title>
</head>
<body>

<?php echo $content_html; ?>

</body>
</html>