S
S
Super Star2019-12-15 20:41:31
Twig
Super Star, 2019-12-15 20:41:31

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 Womens 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>

<?php $i = 0; foreach($banners as $banner): ?>
<?php $i++; endforeach; ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ice, 2019-12-16
@3dben

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 %}

Works in places crookedly, but maybe https://php2twig.com/ will help you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question