Forum
Include Bootstrap Carousel template into Perch blocks
I would like to include the carousel template into perch blocks to be able to reuse it several times into the same page. I built the carousel template as described here: https://forum.grabaperch.com/forum/11-18-2015-bootstrap-carousel-template-for-perch Because it is split into 3 content templates, I tried it with a layout. Here's my code:
Perch block:
<perch:block type="carousel" label="Carousel">
<perch:layout path="refs.carousel">
</perch:block>
Perch layout (named refs.carousel.php):
<?php
perch_content_create('Carousel', array(
'template' => 'carousel-main.html',
'multiple' => true,
));
?>
<?php
perch_content_custom('Carousel', array(
'template' => 'carousel-indicators.html',
));
?>
<?php
perch_content_custom('Carousel', array(
'template' => 'carousel-slides.html',
));
?>
Probably I am on the wrong way... Thanks a lot for your help!
What are you expecting will happen?
I thought the carousel template would appear as it does when I include the code above directly into the page.
That layout is including the result of the
perch_content_custom()
calls in your template. That won't involve any Perch template tags.Ok, I see. But is it even possible to include a region that consists of three templates into Perch blocks? If yes, can you please guide me how to build this? I would like to give this option to the content manager.
You can include another template with the
<perch:template>
tag.I already tried this, I called it «carousel.html»
But what I put into this template? How can I link these multiple templates? What I need is to get it work like the region that uses the three templates, right? Sorry, probably I miss something important!
Hello Martin,
You are using a multi-item region here:
Since you want to use blocks, you need to rework your solution with repeaters inside a block:
You can add your indicators inside
perch:before
orperch:after
.Many thanks, Hussein! That was the missing information, the carousel itself has to be within one single block. It's now working fine – except the indicators... If I add them inside perch:before or perch:after I just get an output for the first item:
So, how can I include the amount of repeated items?
Output:
Thanks again for your appreciated help!
I see!
Perhaps something like this:
The second repeater tags should loop through the items again.
Great, thanks a lot, Hussein!