Forum

Thread tagged as: Question, Runway, Shop

Shop Product Title as Page Title.

I am trying to set the page title as the product title using page layout variables. here is my code:

On product master page:

<?php
    $title = perch_shop_product(perch_get('product'), [ 'template' => 'products/title.html' ]); 

    perch_layout('global/header', array(
        'title' => $title,
        'body-class' => 'product',
    ));
?>

On Perch header layout:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php perch_layout_var('title'); ?></title>
        <?php perch_page_attributes(); ?>

title.html :

<perch:shop id="title" type="text" label="title" />

When I look at the page in browser the product title is being output to the page at the top of the HTML and the <title> tag is left empty. like this:

(test is the product title in this instance)

test
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
        <meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="robots" content="" />   <link href='https://fonts.googleapis.com/css?family=Lora:400,400italic|Work+Sans:300,400,500,600' rel='stylesheet' type='text/css'>
    <link href="/../css/styles.css" rel="stylesheet">
</head>
<body class="product">

My Diagnostics:

Perch Runway: 2.8.31, PHP: 7.0.10, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: 241ae00989d1995ffcbbf63d579943635faf9972 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_blog (5.0), perch_forms (1.8.3), perch_shop_orders (1.0.8), perch_shop_products (1.0.8), perch_shop (1.0.8), perch_members (1.5)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_blog', 'perch_members', 'perch_shop', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/greg/Sites/millers/trunk/perch
PERCH_CORE: /Users/greg/Sites/millers/trunk/perch/core
PERCH_RESFILEPATH: /Users/greg/Sites/millers/trunk/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
HTTP_HOST: millers
DOCUMENT_ROOT: /Users/greg/Sites/millers/trunk
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Any ideas what I am doing wrong or if I am attacking it in totally the wrong way are most welcome, thanks.

Greg Riley

Greg Riley 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to set perch_shop_product() to return the value rather than echo it:

$title = perch_shop_product(perch_get('product'), [ 'template' => 'products/title.html' ], true);

Fantastic, working perfectly now. Thanks Drew.