如果您想从您的Twig文件中添加JavaScript、CSS和HTML,您可以这样做:
{# Add assets into head of the document by using default priority. #}
{% assets in 'head' with { priority: 0 } %}
{% endassets -%}
基本上,可以选择两个可选参数:
in 'x'
with { priority: y }
参数x是您想要添加内容的位置(head和footer目前由Hydrogen主题支持),y是优先级,用于命令资产默认为0,范围从-10到10。
优先级较高的数字被添加到文档中,在任何较低的数字之前。如果有多个具有相同优先级的资产标记,则它们的排序没有定义。
还有一个JavaScript的Twig标签:
{# Add javascript into end of the document (before any other javascript in the footer). #}
{% scripts in 'footer' with { priority: 10 } %}
{% endscripts -%}
只适用于样式表:
{# Add some stylesheets and make them to load last (override other styles). #}
{% styles with { priority: -10 } %}
{% endstyles -%}
在Gantry 5.3+中载入CSS / JS
从Gantry 5.3开始,有一种