Forum
Get Content From Another Page
Hi guys,
I'm trying to use perch_content_custom()
to pull information from a region on another page, but nothing is being returned.
default.php:
<?php if (!defined('PERCH_RUNWAY')) include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php'); ?>
<?php perch_layout('global.header'); ?>
<?php perch_page_attributes(); ?>
<?php
$resources = perch_content_custom('test',array(
'page'=>'/res_centre.php',
'template'=>'resource_centre.html'
));
PerchSystem::set_var('resources_returned',$resources);
?>
<div class="innerwrap">
<?php perch_content('header-image'); ?>
<div class="content-wrapper">
<div class="content-area">
<div class="left-col">
<h3 class="turquoise">more in this section</h3>
<nav class="sidebar">
<?php
perch_pages_navigation(array(
'from-path' => '/solutions',
'levels' => 2
));
?>
</nav>
</div>
<!-- /div.left-col -->
<div class="page-template">
<?php
var_dump($resources);
print_r(PerchSystem::get_vars());
?>
<?php perch_content('page template'); ?>
</div>
<div class="clearfloat"> </div>
<!-- /div.clearfloat -->
</div>
<!-- /div.content-area -->
</div>
<!-- /div.content-wrapper -->
</div>
<!-- /div.innerwrap -->
<?php PerchUtil::output_debug(); ?>
<?php perch_layout('global.footer'); ?>
The $resources variable is coming back NULL.
res_centre.php:
<?php if (!defined('PERCH_RUNWAY')) include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php'); ?>
<?php perch_content_create('test',array('template'=>'resource_centre.html')); ?>
<?php perch_layout('global.header'); ?>
<?php perch_page_attributes(); ?>
<div class="innerwrap">
<?php perch_content('header-image'); ?>
<div class="content-wrapper">
<div class="content-area">
<div class="page-template">
TEST TEST TEST<?php perch_content('resource centre'); ?>
<?php perch_content_custom('test'); ?>
</div>
<div class="clearfloat"> </div>
<!-- /div.clearfloat -->
</div>
<!-- /div.content-area -->
</div>
<!-- /div.content-wrapper -->
</div>
<!-- /div.innerwrap -->
<?php perch_layout('global.footer'); ?>
There are items in the 'test'
region.
Any ideas? Thanks!
Just checking your content is definitely in 'test' not 'resource centre'?
Also, try adding
, true
to theperch_content_custom
call to return the value, rather than output it.Hi Simon,
I found that answer (including
,true
) in another thread, but thanks for that!The issue I'm having now is that the variable isn't outputting anything.
Using
get_vars()
shows that the variable is populated, but using it in the HTML template through<perch:content id="resource-centre"
isn't outputting anything.Any ideas on that?
In your page you've used
PerchSystem::set_var('resources_returned',$resources);
So you'd need to use
resources_returned
in your template:Hi Simon,
Sorry - typo! I'm using:
And nothing's coming back -
TEST - REPUBLISH
outputs, but nothing else.get_vars()
displays the expected output under the name["resources_returned"]
so I'm not sure what's going wrong.In your page code above, I can see you're setting the variable, but I can't see where you're trying to output the template that contains
<perch:content id="resources_returned" />
No worries - this is how that section of my PHP Page looks:
(obviously,
'page template'
is the HTML template that I'm trying to output to.)Change:
to
Hi Drew!
Thanks for the help there - one final question; this is now outputting as a string rather than rendering as HTML.
Any tips?
Add
encode="false"
to the template tag.Sorry, sorted it!
<perch:content id="resources_returned" html="true"/>
Thanks for the help both!