Forum

Thread tagged as: Question

Page title in content template

I have this code in a content template

<section class="inner_banner">
        <div class="container">
            <div class="row">
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                    <h3>About us</h3>
                </div>
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12" style="text-align:right;">
                    <a href="#" class="button_main get_in_touch transition3s">Get in Touch</a>
                </div>
            </div>
        </div>
    </section> 

I want to replace the 'About us' plain text with the Perch page title, however do I achieve this?

Neil Duddridge

Neil Duddridge 1 points

  • 5 years ago
Simon Clay

Simon Clay 127 points

Hi, you can do it by passing it into your template as a variable:

In your page set the variable and, as you see, the region now needs to be perch_content_custom:

<?php 
    $pg_title = perch_pages_title(true); 

    PerchSystem::set_var('page_title', $pg_title);

    perch_content_custom('My region', array(
        'template'=>'template.html'
    ));
?>

In your template:

<section class="inner_banner">
    <div class="container">
        <div class="row">
            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                <h3><perch:content id="page_title" /></h3>
            </div>
            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12" style="text-align:right;">
                <a href="#" class="button_main get_in_touch transition3s">Get in Touch</a>
            </div>
        </div>
    </div>
</section> 

Perfect, thanks Simon

How do I then suppress the field in Perch? Currently it's showing as a blank field. If I use suppress=true then it won't output the page title on the front end.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Use type="hidden"

Of course, thanks.