Forum

Thread tagged as: Problem

Is it possible to use perch_content_custom() in content templates?

In this project's design we have a page called Our Packages and a page called Our Results.

Our Results has a region called Results which is a repeating region.

On Our Packages, we have a region called Packages which uses a custom content template to enable the user to enter the package content. In the design there is a need to pull into this view a particular item from the Results region on the Our Results page, so I was hoping something this would work:

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

<perch:content id="text" type="textarea" label="Text" required="true" />

<h2>Recent Results</h2>

<?php perch_content_custom('Results', array(
    'page' => '/our-results.php',
    'template' => 'result.html',
    'count' => 1, 
    'sort' => 'date', 
    'sort-order' => 'DESC', 
    'filter' => 'package',
    'match' => 'eq', 
    'value' => '<perch:content id="title" type="text" label="Title" urlify="true" />'
)); ?>

This would pull through the latest Result item that meets the filter. However that doesn't get parsed so I'm guessing it's not possible to use perch_content_custom() from within a content template?

Thanks

Russell Back

Russell Back 2 points

  • 7 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Templates are HTML, you can't use PHP in them.

Rachel Andrew said:

Templates are HTML, you can't use PHP in them.

Doh! Sorry what a daft question to ask! Can't believe I didn't see that.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Use perch_content_custom() in the page and then use PerchSystem::set_var() to pass the result into the template.