Forum
perch_content_custom with templates that include another template
Hey guys,
just learned about perch_content_custom(); which is cool but I can't wrap my head around the following thing:
I have this region on my index.html:
<?php perch_content('Photo Series'); ?>
Which I set up to allow multiple of this template (content/photo_series.html):
<div class="images-source" style="display: none;">
<perch:repeater id="photos" label="Photos">
<perch:template path="content/photo_list_item.html" />
</perch:repeater>
</div>
Which in turn obviously allows more than one of this template (content/photo_list_item.html):
<a href="<perch:content id="photo" type="image" width="1200" height="1200" bucket="works" label="Photo please!" />">
<img data-src="<perch:content id="photo" type="image" width="700" height="700" bucket="works" label="One of your magnificent artworks here please!" />">
</a>
All of that works just perfectly (awesome by the way!). But now I'm trying to grab one of those pictures (one picture from the ones contained in one of the many items in "photo_series.html") doing this:
<?php perch_content_custom('Photo Series', array(
'page' => '/index.php',
'template' => '_rand_hero_image.html',
'sort-order' => 'RAND',
'count' => 1
));?>
Through this custom template here:
<figure class="header-artwork" data-image-url="<perch:content id="photo" type="image" width="1200" height="1200" bucket="works" label="Photo please!" />"></figure>
That gives me an empty – which I'm sure is absolutely correct (because it works when I use any perch:content from "photo_series.html" instead of the one here which is in "photo_list_item.html".
Any ideas?
Thanks guys – you're awesome!
Ah and what just came to mind was instead of going through all that trouble, can I somehow grab a random item from an asset bucket? Still telling the snippet to get me the 1200px version of that image though ...
Thanks!
Your template needs to always include the repeater tags.
like that?
Because that kinda works but gives me – funny enough – exactly 5 times the same filled template.
It should be the contents of your repeater.
Are you using content regions or collections?