Forum
If/Else Template
Hello,
For my carousel, I need to output carousel-item active for the first image, and then carousel-item for the remaining images. I thought I could use Perch's if/else. Here's my code:
<perch:before>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
</perch:before>
<perch:if id="1">
<div class="carousel-item active" style="background-image: url('<perch:content id="carousel_image" type="image" w="1900" h="1080" label="Carousel image">')">
<div class="carousel-caption d-none d-md-block">
<h3><perch:content id="carousel_title" type="text" label="Carousel title" required></h3>
<perch:content id="carousel_body" type="textarea" label="Carousel body" markdown editor="markitup">
</div>
</div>
<perch:else>
<div class="carousel-item" style="background-image: url('<perch:content id="carousel_image" type="image" w="1900" h="1080" label="Carousel image">')">
<div class="carousel-caption d-none d-md-block">
<h3><perch:content id="carousel_title" type="text" label="Carousel title" required></h3>
<perch:content id="carousel_body" type="textarea" label="Carousel body" markdown editor="markitup">
</div>
</div>
</perch:if>
<perch:after>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</perch:after>
The content item's ID is actually 3 (for the first image) and I tried that as well. The code is outputting carousel-item active for all content items.
Thank you for your help.
<perch:if id="1">
That does't seem right...
I think you want:
<perch:if exists="perch_item_first">
https://docs.grabaperch.com/templates/attributes/id/