Forum

Thread tagged as: Question

Page titles

Is there a way for me to get the heading inside my template to be shown as the page title? Tried a few diff methods but cant get any of them to work. Want my heading, which also is the slub, to be my page title.

Erick Green

Erick Green 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, I'm sure. Can you show us the code you're using? We'd need some context to be able to help.

This is my project.php file:

        <?php
        perch_content_custom('Projects', array(
          'page' => '/strategy.php',
          'template' => 'projects-template.html',
          'filter' => 'slug',
          'match' => 'eq',
          'value' => perch_get('s'),
          'count' => 1,
        ));
        ?>

This is my projects-template.html:

<perch:content id="Overviewphoto" type="image" label="Overviewphoto" quality="45" crop="true" width="1000" height="600" output="tag" suppress="true"/>
<h1><perch:content id="slug" for="title" type="slug" suppress="true" /></h1>
<h1><perch:content id="title" type="text" label="Title" required="true" title="true" /></h1>
<perch:content id="body" type="textarea" label="Content" textile="true" editor="markitup" />
<perch:repeater id="photo" label="Projectphotos">
    <perch:content type="image" id="image" label="Projectphotos" quality="65" width="1600" output="tag" />
</perch:repeater>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which is the field you want to use as a title?

One of these:

<h1><perch:content id="slug" for="title" type="slug" suppress="true" /></h1>

Or

<h1><perch:content id="title" type="text" label="Title" required="true" title="true" /></h1>
Drew McLellan

Drew McLellan 2638 points
Perch Support

So you could do this:

$result = perch_content_custom('Projects', array(
          'page' => '/strategy.php',
          'filter' => 'slug',
          'match' => 'eq',
          'value' => perch_get('s'),
          'skip-template' => true,
        ));
PerchSystem::set_var('title', $result['title']);

My content don't show with 'skip-template', or maybe i've done something wrong?

Where exactly shall i paste your code? Sorry, not an php expert at all.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

This is just to retrieve the heading, don't replace your existing code with this.

Documentation for perch_content_custom is here https://docs.grabaperch.com/docs/content/perch-content-custom/

The code Drew has given you is used to write the title from your content into a variable so it can be used in the title of your page, so you need to add this to your detail page.

I understand. So I placed the code Drew wrote me but cant find the part in your link where i can get the information out from the variable. I'm looking to make a page title as "My customer - title from the inside the template".

Thanks in advance

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you outputting the value in your template?

No not yet. Can't find what code to place there.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Should just be:

<perch:content id="title" type="text" />

I have now this code in my strategy.php file:

<?php
$result = perch_content_custom('Projects', array(
          'page' => '/strategy.php',
          'filter' => 'slug',
          'match' => 'eq',
          'value' => perch_get('s'),
          'skip-template' => true,
        ));
PerchSystem::set_var('title', $result['title']);
?>

Ive tried to put this code in my <title></title> but couldnt get it the title. What have ive done wrong?

<perch:content id="title" type="text" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does <perch:showall /> output?

Outputs Page - <perch:showall />. I've got this to work with my blog using the code:

<title><?php perch_blog_post_field(perch_get('s'), 'postTitle'); ?></title>

Is there a way to use this same technique to get the id="title" inside my perch_content_custom template?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I mean in the template where you're trying to use the title.

What shall I look for? I dont want to have <perch:showall /> there for a long time since my page is already live. It was very easy to get this to work properly with the blog app. Is there a way to use this same technique to get the id="title" inside my perch_content_custom template?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you not try it in your dev environment?

Click the link to see the output from <perch:showall />

https://www.dunderverk.no/prosjekter/perchshowall.html

Drew McLellan

Drew McLellan 2638 points
Perch Support

So it looks like title is set:

title   Ny nettløsning med blogg for Henrik Kristoffersen

Is that what you'd expect it to be?