gpt4 book ai didi

javascript - Shopify - 在 js.liquid 和 scss.liquid 文件中使用 if 语句

转载 作者:太空宇宙 更新时间:2023-11-04 02:00:58 38 4
gpt4 key购买 nike

我正在尝试将 JS 文件合并到一个文件中,但是我需要使用 js 文件中的 if 语句设置条件。

我已经创建了 file.js.liquid 但它似乎不起作用;例如,我添加了一个测试:

{% if template contains 'index' %}
console.log('homepage loaded');
{% endif %}

我正在尝试做的事情的例子,当然还有很多我需要做的。

{% if settings.the_simpsons_enabled and settings.simpsons_video_enable %}
// video popup
$(".video-popup").videoPopup();
{% endif %}

条件语句在 scss.liquid 文件中也不起作用:

{% if template contains 'index' or template contains 'collection' or template contains 'product' %}
@import url("{{ 'owl.carousel.scss' | asset_url }}");
{% endif %}

有什么想法为什么不起作用或者它是否可能?我假设它是一个液体文件。

最佳答案

CSS 或 JS 等文件的 Liquid 扩展允许使用 Liquid 变量,但不允许使用语句。

所以 {{ write_my_liquid_var_here }} 会起作用。 {% if liquid_statement %}做某事{% endif %}不会。

关于javascript - Shopify - 在 js.liquid 和 scss.liquid 文件中使用 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41763049/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com