Carlsbad Raceway
Carlsbad Raceway

Reputation: 11

Trying To Expand on TWIG "if" and "for" test In common/footer.twig of OpenCart 3.0.3.2

I am looking to expand on the "if" and "for" tests ability in OpenCart 3.0.3.2 ... I have never honestly experienced TWIG (I am comfortable in perl) so I will do my best not to annoy or off-put anyone.

In the OpenCart back-end: Design -> Theme Editor I am working on the TWIG file: common/footer.twig Specifically I am working on the first column "informations" exhibited below.

{% if informations %}
<div class="col-sm-3">
<h5>{{ text_information }}</h5>
<ul class="list-unstyled">

{% for information in informations %}

<li> <a style="font-size: 10pt;" href="{{ information.href }}">
<i style="color: #FFCC00; font-size: 9pt;margin-right: 2px;" aria-hidden="true" class="fas fa-info"></i> 
{{ information.title }}</a></li>

{% endfor %}

</ul>
</div>
{% endif %}

The above "if" and "for" tests are returning the site operators defined values from
Catalog -> Information - "informations" [privacy, terms, refund, etc,] to be displayed as anchors in the footer.

To this point I have tried to formulate what I thought would work, however I was only able to produce application errors at worst or absolutely nothing would print from the tests I conjured.

Below I will embarrass myself with my attempt that fails by not printing anything.

{% if informations %}
<div class="col-sm-3">
<h5>{{ text_information }}</h5>
<ul class="list-unstyled">
{% for information in informations == "Privacy Policy" %}
<li> <a style="font-size: 10pt;" href="{{ information.href }}">
<i style="color: #FFCC00; font-size: 10pt;margin-right: 2px;"  aria-hidden="true" class="fas fa-user-secret"></i> {{ information.title }}</a></li>

 {% endfor %}

 </ul>
 </div>

{% endif %} 

What I would like to achieve is to expand on the TWIG "if" and "for" tests so that it can be determined if one of those returned values be "Privacy Policy" OR "Delivery Information" in example, the text information would be printed to the footer in addition to an appropriate Font Awesome icon pertinent to the value.

Any input would be greatly appreciated and I thank you in advance for taking the time to read this let alone reply.

Best Regards

Upvotes: 0

Views: 96

Answers (1)

Chase
Chase

Reputation: 9362

The main reason you are not seeing any output is that your syntax is off.

{% for information in informations == "Privacy Policy" %}

Thats not going to do what you expect. What you want to do instead is just check within the loop a particular value and act accordingly:

{% if informations %}
<div class="col-sm-3">
    <h5>{{ text_information }}</h5>
    <ul class="list-unstyled">
    {% for information in informations %}
        {% if information.title == "Privacy Policy" %}
            <li>
                <a style="font-size: 10pt;" href="{{ information.href }}">
                    <i style="color: #FFCC00; font-size: 10pt;margin-right: 2px;" aria-hidden="true" class="fas fa-user-secret"></i> {{ information.title }}
                </a>
           </li>
        {% else %}
            <li>
                <a style="font-size: 10pt;" href="{{ information.href }}">
                    {{ information.title }}
                </a>
           </li>
        {% endif %}
    {% endfor %}
    </ul>
</div>
{% endif %} 

Notice the nested if check on the information.title.

Upvotes: 1

Related Questions