嵌套在液体标签中的Shopify液体标签 - 有解决方法吗?

发布于 2025-02-06 16:00:15 字数 1027 浏览 1 评论 0原文

我是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话已封尘 2025-02-13 16:00:15

我建议为您的所有巧克力创建片段,并使用标签作为输出所需内容的变量。

的讨论中更明确。

这是我的意思的视觉表示,并且从您与@fabio filippi smippets/Chocolate.liquid

{% assign tag_image = tag | append: '.png' %}

{% case tag %}
  {% when 'diet' %}
    <img src="{{ tag_image | file_img_url: '100x' }}" class="responsive" />

  {% when 'dark' %}
    <div>My dark chocolate HTML</div>

  {% when 'white' %}
    <div>My white chocolate HTML</div>

{% endcase %}

以及如何使用中

{% render 'chocolate', tag: tag %}

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

{% assign tag_image = tag | append: '.png' %}

{% case tag %}
  {% when 'diet' %}
    <img src="{{ tag_image | file_img_url: '100x' }}" class="responsive" />

  {% when 'dark' %}
    <div>My dark chocolate HTML</div>

  {% when 'white' %}
    <div>My white chocolate HTML</div>

{% endcase %}

and how to use:

{% render 'chocolate', tag: tag %}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文