Answer the question
In order to leave comments, you need to log in
How to write this with twig?
Hello. I'm taking a course on opencart. There is no template yet. Everything is old fashioned. The documentation for the template engine is poor.
I have a carousel. We need to output points and slides, but how to do it with twig? Here is what is written by the usual php template engine and there is just a problem ( highlighted in bold ). I don't know how to implement it with twig)
<div class="carousel-indicators-wrap">
<ol class="carousel-indicators">
{% for banner in banners %}
<li data-target="#carousel" data-slide-to="<?=$i?>"<?php if($i == 0) echo ' class="active"' ?>></li>
{% endfor %}
</ol>
</div><!-- /.carousel-indicators-wrap -->
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php $i = 0; foreach($banners as $banner): ?>
<div class="item<?php if($i == 0) echo ' active' ?>">
<div class="bgslide" style="background-image: url(<?=$banner['image']?>);"></div>
<div class="container">
<div class="carousel-caption">
<h3><?=$banner['title']?></h3>
<?php if($banner['link']): ?>
<a href="<?=$banner['link']?>" class="btn-red">Shop Women’s Apparel</a>
<?php endif; ?>
</div>
</div>
</div>
<?php $i++; endforeach; ?>
</div>
<b><li data-target="#carousel"
data-slide-to="<?=$i?>"
<?php if($i == 0) echo ' class="active"' ?>></b>
</li>
Answer the question
In order to leave comments, you need to log in
https://twig.symfony.com/doc/3.x/tags/for.html
use for
{% for banner in banners %}
<li data-target="#carousel" data-slide-to="{{ loop.index }}" {% if loop.index == 1 %} class="active" {% endif %} ></li>
{% endfor %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question