Forum

Thread tagged as: Question

perch_content_custom() and HTML Templates

Hi guys,

I'm trying to pull in a dynamically populated list of resources (that are on another page) into the sidebar of one of my pages.

The sidebar is inside an HTML template, as there is a checkbox that controls whether or not to show it.

The difficulty I'm having is that I need to use perch_content_custom() to call the list (as I'll need to pass parameters to filter on), but I obviously can't do that from within my HTML template.

PHP Page:

<?php if (!defined('PERCH_RUNWAY')) include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php'); ?>
<?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="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 perch_content('page template'); ?>
      </div>
      <div class="clearfloat"> </div>
      <!-- /div.clearfloat --> 

    </div>
    <!-- /div.content-area --> 
  </div>

  <!-- /div.content-wrapper --> 

</div>
<!-- /div.innerwrap -->

<?php perch_layout('global.footer'); ?>

HTML Template (sidebar is the Super Right Column, and the list should go under 'Resources'):

<div class="page-template">
<div class="right-col <perch:if exists="show-right">when-to-use_active</perch:if>">

    <perch:content id="content" type="textarea" label="Content" markdown="true" editor="markitup" imagewidth="640" imageheight="480" />

</div>
<!-- /div.left-col --> 
<perch:content id="show-right" type="checkbox" label="Show Right Column?" value="show-right" suppress="true" />
<perch:if exists="show-right">
    <div class="super-right-col">
        <perch:if exists="wtu">
            <div id="when-to-use">
                <h3 class="turquoise">When to use this solution</h3>
                <img src="<perch:content width="700" id="wtu_image" type="image" label="When to Use - Image" />" alt="<perch:content id="wtu_image-alt" type="text" label="When to Use - Image ALT Tag" />" title="<perch:content id="wtu_image-alt" type="text" label="When to Use - Image ALT Tag" />"/>
                <h4><perch:content type="text" id="wtu-head" label="Title"/></h4>
                <perch:content id="wtu" type="textarea" label="When to Use - Text" markdown="true" textile="true" editor="markitup" size="xs"/>
            </div>
        </perch:if>
        <perch:if exists="show-resources">
            <div id="resources">
                <perch:content id="show-resources" type="checkbox" label="Show Resources?" value="resources" suppress="true" />
                <h3 class="turquoise">Resources</h3>
            </div>
        </perch:if>
    </div>
</perch:if>
</div>
<!-- /div.page-template -->

I was thinking about getting the information on the PHP page at the top, iterating through each result to build up a <ul> containing <li> items and then store that as a variable I can pass through to the template using PerchSystem::set_var() - is this possible/advisable?

Thanks for any help! Harry

Harry Ray

Harry Ray 0 points

  • 4 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

You can return the templated HTML then pass that as a variable into your template, there is no need for you to do the work yourself.

Hi Rachel,

Thanks for the help - a little confused though! What do you mean by 'return the templated HTML'? Do you mean use perch_content_custom() to call in the list with a template, store that as a variable and then pass that to my sidebar template?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Yep - you can return the HTML, as detailed in the various parameters in the docs. I've just got on a plane and they are going to make me put this laptop away so it would probably be quicker for you to take a look at that than wait for me to write you an example :)

https://docs.grabaperch.com/functions/content/perch-content-custom/

Thanks for the help! Enjoy wherever you're flying to!