component

component组件是隔离作用域的,如果需要外部变量需要手动通过hash参数传入,Sline全局object不限制。

渲染指定的公共组件,组件可以是全局组件(component目录下)或者私有section/block组件(对应section/block目录下)。

{{#component file_path [hash...] /}}

file_path

组件文件路径,可以是相对路径或者绝对路径,相对路径需要以 ./ 开头,绝对路径就是components/下的文件。

hash

动态hash参数(key=value),不限制个数,用于传入component中需要的变量参数。

例子

使用全局组件

导入全局components/title.html组件。

{{#component "title" /}}

引入私有组件

比如当前在 sections/header/header.html 模板中,使用 sections/header/title.html 模板。

{{#component "./title" /}}

组件传递参数

例如要把section.settings.title中的变量传入到title组件内。

<!--! sections/header/header.html -->
{{#component "./title" title=section.settings.title show=true /}}
<!--! sections/header/title.html -->
{{#if show}}
{{ title }}
{{/if}}
这篇文章对你有帮助吗?