Forum

Thread tagged as: Question, Problem, Shop

Using Perch Shop product data in Meta

Hi, I have perch shop install and use a product template page to show all my product listings on.

in my product page, I have the following code to pull out the product

<?php perch_shop_product(perch_get('s'));?>

What is the best way of getting the title out of the listing to use in my <title> tag?

I've tried the following with no success

<?php perch_shop_product(perch_get('s'), [
    'template' => 'product-meta.html']
    );?>]

And heres how I'm calling that data in the product-meta.html file

<title><perch:shop id="title" type="text" label="Title" required="true" order="2"/></title>

Any ideas where I'm going wrong or some tips on the best way of doing this? Ideally I want the client to be able to set the page title and any meta data when they add the product.

Nik Gill

Nik Gill 1 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

How was it failing?

Hi Drew

It's displaying nothing at all, not even empty <title> tags

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Have you tried enabling debug so you can see if your template is being used?

https://docs.grabaperch.com/perch/configuration/debug/

Ah! Right I have enabled debug and saw that my template wasn't where perch expected it to be...

Perch was looking for it in addons > apps > perch_shop > templates > shop (just in this folder and not in a sub folder oddly)

I'd got it in perch > templates > shop > products (which is where I thought it should go due to the fact that I'm basically duplicating the product)

It's working now... though I'm really not sure the template should be located there at all

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

You should be able to leave it in the products folder:

perch_shop_product(perch_get('s'), [
'template' => 'products/product-meta.html',
]);

Cheers, will try that Hussein