嵌套在液体标签中的Shopify液体标签 - 有解决方法吗?
我是Shopify和Liquid的新手。我知道您不能在另一个液体标签中嵌套液体标签,即:
{% something {{ something_else }} %}
我想知道这种情况是否有解决方法?可能涉及“捕获”或巧妙地使用“ RAW”?
我正在建立一个使用产品标签来表示哪些巧克力(巧克力收集)的网站。在产品页面上,我可以轻松地将标签作为列表返回:
<ul class="chocolates-menu">
{% for tag in product.tags %}
<li><a href="/collections/all/{{ tag | handleize }}">{{ tag }}</a></li>
{% endfor %}
</ul>
但是,我想用文件名渲染巧克力描述)IE:
<li><a href="/collections/all/{{ tag | handleize }}">{% render '{{ tag }}' %}</a></li>
我最接近的是:
{% for tag in product.tags %}
{% capture chocolate_tag %}
{% raw %}{% render{% endraw %} {% raw %}'{% endraw %}{{ tag }}{% raw %}' %}{% endraw %}
{% endcapture %}
<li><a href="/collections/all/{{ tag | handleize }}">{{ chocolate_tag }}</a></li>
{% endfor %}
这将输出正确的代码,但作为页面上的文本(而不是解析)。 IE:{%渲染'tag名称'%}作为列表项目的文本。更加明亮的人的任何帮助都非常感谢。谢谢。
I'm new to Shopify and Liquid. I know that you can't nest a liquid tag within another liquid tag ie:
{% something {{ something_else }} %}
I was wondering if there is a workaround for this kind of scenario? Possibly involving 'capture' or clever use of 'raw'?
I'm building a site that uses product tags to denote which chocolates go in which products (collection of chocolates). On the product page I can easily return the tags as a list:
<ul class="chocolates-menu">
{% for tag in product.tags %}
<li><a href="/collections/all/{{ tag | handleize }}">{{ tag }}</a></li>
{% endfor %}
</ul>
However, I'd like to render snippets with file names to match the names of the tags (these will contain an image, chocolate name and chocolate description) ie:
<li><a href="/collections/all/{{ tag | handleize }}">{% render '{{ tag }}' %}</a></li>
The closest I've got is:
{% for tag in product.tags %}
{% capture chocolate_tag %}
{% raw %}{% render{% endraw %} {% raw %}'{% endraw %}{{ tag }}{% raw %}' %}{% endraw %}
{% endcapture %}
<li><a href="/collections/all/{{ tag | handleize }}">{{ chocolate_tag }}</a></li>
{% endfor %}
This will output the correct code but as text on the page (rather than parsing it). ie: {% render 'Tag Name Here' %} simply as the text of the list item. Any help from brighter folk, is much appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议为您的所有巧克力创建片段,并使用标签作为输出所需内容的变量。
的讨论中更明确。
这是我的意思的视觉表示,并且从您与@fabio filippi
smippets/Chocolate.liquid
以及如何使用中
I would suggest creating a snippet for all your chocolates and using the tag as a variable to output what is needed.
Here is a visual representation of what I mean and is kinda clearer from your discussion with @Fabio Filippi
snippets/chocolate.liquid
and how to use: