Forum

Thread tagged as: Question, Problem

Duplicating perch content using a different template

Hello, I have a system where the client upload images to both a gallery and a slideshow. I am trying to install a fallback where if the client doesn't enter any images in the slide show the system will use the images uploaded to the gallery, but with a different template. Code so far is:

<?php   

    perch_content_create('Artwork Slideshow', array(  'template' => '_artwork/_artwork_slide.html',  'multiple' => true, 'add-to-top' => true,  ));  
    perch_content_create('Artwork Images', array( 'template' => '_artwork/_artwork_image.html', 'multiple' => true, 'add-to-top' => true, )); 

    $slideshow = perch_content('Artwork Slideshow', true);  
    $images = perch_content('Artwork Images', true);  
    $fallback = perch_content_custom('Artwork Images', ['template'=>'_artwork/_artwork_slide.html']);

?>

<div class="imageSlides">
    <?php echo ctype_space($slideshow) ? $slideshow : $fallback.'FallBack Invoked'; ?>
</div><!--/.imageSlides-->

Any ideas why it's not working? The fallback is being invoked but no content is being returned.

P.S. - I use 'ctype_space' as 'empty' and '!isset' don't work as the perch system is returning something for regions with an item count of 0.

Tony Astley

Tony Astley 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_content_custom() echoes by default. Pass true as the final argument.

$fallback = perch_content_custom('Artwork Images', ['template'=>'_artwork/_artwork_slide.html'], true);