Forum

Thread tagged as: Question, Blog

Is is possible to use a blog variable in a standard template

Diagnostic Report: Perch is out of date. You are running Perch 2.8.15 and the latest is 2.8.26. PHP 5.5.32 is up to date MySQL 5.5.47 is up to date Image processing available

Summary information

Perch: 2.8.15, PHP: 5.5.32, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 15d5c781cfcad91193dceae1d2cdd127674ddb3e $, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (2.8.15), assets (2.8.15), categories (2.8.15), perch_blog (5.0), perch_forms (1.8.3)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_blog', );
PERCH_LOGINPATH: /cms
PERCH_PATH: /home/sites/juanfernandes.co.uk/public_html/cms
PERCH_CORE: /home/sites/juanfernandes.co.uk/public_html/cms/core
PERCH_RESFILEPATH: /home/sites/juanfernandes.co.uk/public_html/cms/resources
Image manipulation: GD
PHP limits: Max upload 64M, Max POST 64M, Memory: 128M, Total max file upload: 64M
Resource folder writeable: Yes
HTTP_HOST: juanfernandes.co.uk
DOCUMENT_ROOT: /home/sites/juanfernandes.co.uk/public_html/
REQUEST_URI: /cms/core/settings/diagnostics/
SCRIPT_NAME: /cms/core/settings/diagnostics/index.php

Top part of post.php

<?php include('../cms/runtime.php');?>
 <!doctype html>
  <?php perch_layout('global.header'); ?>
   <body>
    <div class="page blog-post">
      <header class="page__header" role="banner">
        <?php perch_content('Logo'); ?>
        <?php
            perch_pages_navigation(array(
            'template' => array('item.html')
            ));
          ?>
       </header>
       <?php perch_content('Page Intro'); ?>
       <main role="main">
        <div class="container">
          <div class="content">
            <h2 class="content__heading"><?php perch_content('Sub Heading'); ?></h2>
          <div class="row">
            <div class="cols twelve">
              <?php perch_blog_post(perch_get('s')); ?>
...

Perch content template - Page Intro

        <div class="intro" style="background-image: url('<perch:content type="image" id="intro-image" label="Intro Image" />');">
          <div class="intro__content">
            <h1 class="intro__heading">
              <span class="intro__heading--large"><perch:blog id="postTitle" type="text" /></span>
                <perch:content type="text" id="page-intro-heading-small" label="Heading Small" required="true" />
            </h1>
          </div><!-- /.intro__content -->
        </div><!-- /.intro -->

I'm trying to get the blog post title to show within the perch content template that is being used in post.php - using <perch:blog id="postTitle" type="text" />.

Is this possible?

Thanks

Juan Fernandes

Juan Fernandes 0 points

  • 5 years ago
Simon Clay

Simon Clay 127 points

Hi Juan,

You could do it if you switch to using perch_content_custom for 'Page Intro':

replace

<?php perch_content('Page Intro'); ?>

with:

<?php 

  //set the title as a variable
  $title = perch_blog_post_field(perch_get('s'), 'postTitle', true);

  //pass it into the content template
  PerchSystem::set_var('postTitle', $title);

  //call the Page Intro content as custom
  perch_content_custom('Page Intro', array(
  'template'=>'yourTemplate.html' // <--- use your template name here
  ));

?>

then, in your template, replace:

<perch:blog id="postTitle" type="text" />

with:

<perch:content id="postTitle" />

Thanks Simon, I'll give that a try later on.