简体   繁体   中英

Liquid - if contains statement not working in for loop

I have a very basic conditional inside a loop that isn't working:

{% for tag in collections.all.tags %} 
     <li class="mb-1 ">
        <a class="text-white" title="{{ tag }}" href="#">
            {{ tag | handle }}
            {% if canonical_url contains tag | handle %}
                active
            {% endif %}
        </a>
     </li>
{% endfor %}

Right now, my tag | handle tag | handle is "dodge" and if I print my {{ canonical_url }} I get https://localhost:3000/collections/all/dodge so my conditional should evaluate to truthy and print the word 'active'.

If I modify my statement to {% if canonical_url contains 'dodge' %} it works fine but I need it to be dynamic. Any suggestions?

将句柄设置为变量,并使用变量而不是句柄进行比较。

First You have to assign value of tag handle to shopify liquid variable & then you will be able to use variable in condition And then every thing will be working fine & dynamic. Thanks !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM