You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shopify集合标题匹配文本输出问题:Liquid代码无内容输出排查求助

Troubleshooting Liquid Code for Shopify Collection Title Matching

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 03:33:11