Forum

Thread tagged as: Question

Filtering perch_content_custom() if content exists

Hi

Is there a way of filtering using perch_content_custom to only display the results that have content within a perch:content tag on another template?

I've got a perch_content_custom region set up on the home page to show client testimonials taken from the main case study pages, but not all case studies include a testimonial so it's showing blank template if there is no content in the testimonials content field.

I've got <perch:if exists="QuoteShort"> in the template but it is still showing a blank testimonial rather than filtering them out completely.

I suppose what I'm trying to archive is a combination of perch_content_custom and <perch:if exists="">. Something like...

'filter' => 'QuoteShort',
                        'match' => 'contains some content',
                        'value' => 'true'

Many thanks

Glen

Glen Piggott

Glen Piggott 0 points

  • 3 years ago

Page template...

perch_content_custom('Case Study Content', array(
                        'page' => array('/air-conditioning/case-studies/*', '/air-source-heat-pumps/case-studies/*'),
                        'template' => '_testimonials.html',
                        'sort' => 'h1',
                        'sort-order' => 'RAND',
                        'count' => '1'
                    ));

Content template...

<perch:if exists="QuoteShort">
                    <p><i class="fa fa-quote-left" aria-hidden="true"></i> <perch:content id="QuoteShort" type="textarea" chars="350" append="..." html="true" /> <i class="fa fa-quote-right" aria-hidden="true"></i></p>
                    <p><perch:content id="clientName" type="text" /></p>
                    <perch:if exists="logo"><p><img src="<perch:content type="image" id="logo" />" alt="<perch:content id="h1" type="text" />"></p></perch:if>
</perch:if> 
Drew McLellan

Drew McLellan 2638 points
Perch Support

'filter' => 'QuoteShort', 
'match' => 'neq', 
'value' => '',

So simple!

Thanks Drew