Forum

Thread tagged as: Question

Bootstrap carousel

I have a carousel template to reuse on the same page. How do I achieve that each of them has a unique id, like

 <div id="carousel_1" class="carousel slide" data-ride="carousel">
...
</div>

 <div id="carousel_2" class="carousel slide" data-ride="carousel">
...
</div>

Thank you for your much appreciated help!

Martin Stettler

Martin Stettler 0 points

  • 4 years ago
Simon Clay

Simon Clay 127 points

Hi Martin, you can use: <perch:content id="perch_item_index" type="hidden" />

eg:

<div id="carousel_<perch:content id="perch_item_index" type="hidden" />" class="carousel slide" data-ride="carousel">
 ... 
</div>  
<div id="carousel_<perch:content id="perch_item_index" type="hidden" />" class="carousel slide" data-ride="carousel">
 ... 
</div>

Cool, that working! Thanx! One last question: any idea how to address only carousels? It's because there are other Perch items on that page, too. So the numbering is not 1, 2, 3.

Simon Clay

Simon Clay 127 points

Are you using a multi-item region, or perhaps a repeater for the carousel? In those instances I would expect it to be restricted to within the carousel in that case. Can you show your template?

It's a multi-item region with total 5 items. How can I make it restricted to the carousel? Have a look please:

<perch:blocks>

    <perch:block type="image" label="Image">
    …
        </perch:block>

    <perch:block type="slider" label="Slider">
        <div id="carousel_<perch:content id="perch_item_index" type="hidden" />" class="carousel slide" data-ride="carousel">
        …
        </div>
        </perch:block>

    <perch:block type="rollover" label="Rollover">
    …
        </perch:block>

    <perch:block type="rolloverSlider" label="Rollover-Slider">
    …
        </perch:block>

    <perch:block type="helper" label="Layout-Helper">
    …
        </perch:block>

</perch:blocks>

Thank you, Simon!

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'll not be able to in that instance. Are you adding a block per slide state? I think you'll need to encapsulate the entire slider as one block and use a repeater for the slides.

Not sure how to encapsulate the slider. The slider is one of 5 items that can be put into the content of that page. The slider is one block (the second one) and I already use a repeater for the slides...

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great. So is the count for the sliders (i.e. multiple sliders on the page) or for the slides within a slider?

It's for the sliders as I have multiple sliders on the page.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's sliders all the way down!

I can't think of a good way to do that from the template. Do they need to be sequential?

It would have been nice, just because the order of the items could change. Thanks anyway, Drew!