A
A
Alexey Goncharov2021-03-26 11:49:05
opencart
Alexey Goncharov, 2021-03-26 11:49:05

How to display the first 6 menu items and not all at once in opencart code?

There is this code:

<ul class="us-footer-list  list-unstyled">
    {% for information in informations %}
    <li class="us-footer-item us-footer-information"><a href="{{ information.href }}" {% if information.rel is defined and information.rel %}rel="nofollow"{% endif %} class="us-footer-link">{{ information.title }}</a></li>
    {% endfor %}
</ul>


This code outputs all li elements in ul at once, but I only need the first six.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Talalaev, 2021-03-26
@asd1982

Since you are using Twig as your template engine, you can do this :

<ul class="us-footer-list  list-unstyled">
    {% for information in informations | slice(0, 6) %}
    <li class="us-footer-item us-footer-information"><a href="{{ information.href }}" {% if information.rel is defined and information.rel %}rel="nofollow"{% endif %} class="us-footer-link">{{ information.title }}</a></li>
    {% endfor %}
</ul>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question