Shopify集合标题匹配文本输出问题:Liquid代码无内容输出排查求助
Hey there, let's break down why your Liquid code isn't outputting the content you want and fix it step by step—since you're new to Liquid, small details can trip you up!
First, let's look at the issues in your current code and how to address them:
1. Fix the HTML structure mismatch
Your original code has the closing </div> outside the {% endif %} block. That means even when the condition isn't met, that closing tag will still render, which can break your HTML structure. Move it inside the conditional block:
{% if collection.title contains 'YourTargetText' %} <div class="lfl_text"> <p>output this text</p> </div> {% endif %}
2. Watch out for case sensitivity
Liquid's contains filter is case-sensitive! If your collection title is "Summer Collection" but you're checking for 'summer', it won't match. To confirm what you're working with, add a debug line to print the actual collection title:
<!-- Add this temporarily to see the exact title --> <p>Debug: Current collection title is "{{ collection.title }}"</p>
Once you see the exact title (including capitalization, spaces, or special characters), use that exact string (or adjust for case with a filter).
3. Normalize case to avoid sensitivity issues
If you don't care about case matching, convert both the collection title and your target text to lowercase:
{% if collection.title | downcase contains 'text' %} <div class="lfl_text"> <p>output this text</p> </div> {% endif %}
This way, "Text", "TEXT", or "text" will all trigger the condition.
4. Confirm your code is in the right context
Make sure you're adding this code in a collection template (like collection.liquid or a section that's loaded on collection pages). If you put it in a product template or a page where the collection object isn't available, the condition will never be true.
5. Add an else branch for debugging
To verify if the condition is actually failing, add an else block to show a message when it doesn't match:
{% if collection.title contains 'text' %} <div class="lfl_text"> <p>output this text</p> </div> {% else %} <p>Debug: Collection title doesn't contain 'text' — current title is "{{ collection.title }}"</p> {% endif %}
This will tell you exactly what's happening and help you tweak your target string.
Start with these steps, and you should get your content showing up in no time!
内容的提问来源于stack exchange,提问作者anton_nv

