mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 06:50:47 -07:00
docs: add jekyllInclude to tutorials
This commit is contained in:
@@ -72,6 +72,8 @@ This way, you don't need to escape `"` in the filename expression.
|
|||||||
|
|
||||||
## Jekyll include
|
## Jekyll include
|
||||||
|
|
||||||
|
{% since %}v9.33.0{% endsince %}
|
||||||
|
|
||||||
[jekyllInclude][jekyllInclude] is used to enable Jekyll-like include syntax. Defaults to `false`, when set to `true`:
|
[jekyllInclude][jekyllInclude] is used to enable Jekyll-like include syntax. Defaults to `false`, when set to `true`:
|
||||||
|
|
||||||
- Filename will be static: `dynamicPartials` now defaults to `false` (instead of `true`). And you can set `dynamicPartials` back to `true`.
|
- Filename will be static: `dynamicPartials` now defaults to `false` (instead of `true`). And you can set `dynamicPartials` back to `true`.
|
||||||
@@ -81,24 +83,28 @@ This way, you don't need to escape `"` in the filename expression.
|
|||||||
For example, the following template:
|
For example, the following template:
|
||||||
|
|
||||||
```liquid
|
```liquid
|
||||||
{% include name.html header="HEADER" content="CONTENT" %}
|
{% include article.html header="HEADER" content="CONTENT" %}
|
||||||
```
|
```
|
||||||
|
|
||||||
`name.html` with following content:
|
`article.html` with following content:
|
||||||
|
|
||||||
```liquid
|
```liquid
|
||||||
<header>{{include.header}}</header>
|
<article>
|
||||||
{{include.content}}
|
<header>{{include.header}}</header>
|
||||||
|
{{include.content}}
|
||||||
|
</article>
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that we're referencing the first parameter by `include.header` instead of `header`. Will output following:
|
Note that we're referencing the first parameter by `include.header` instead of `header`. Will output following:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<header>HEADER</header>
|
<article>
|
||||||
CONTENT
|
<header>HEADER</header>
|
||||||
|
CONTENT
|
||||||
|
</article>
|
||||||
```
|
```
|
||||||
|
|
||||||
[extname]: ../api/interfaces/liquid_options_.liquidoptions.html#Optional-extname
|
[extname]: ../api/interfaces/liquid_options_.liquidoptions.html#Optional-extname
|
||||||
[root]: ../api/interfaces/liquid_options_.liquidoptions.html#Optional-root
|
[root]: ../api/interfaces/liquid_options_.liquidoptions.html#Optional-root
|
||||||
[dynamicPartials]: ../api/interfaces/liquid_options_.liquidoptions.html#dynamicPartials
|
[dynamicPartials]: ../api/interfaces/liquid_options_.liquidoptions.html#Optional-dynamicPartials
|
||||||
[jekyllInclude]: ../api/interfaces/liquid_options_.liquidoptions.html#jekyllInclude
|
[jekyllInclude]: ../api/interfaces/liquid_options_.liquidoptions.html#Optional-jekyllInclude
|
||||||
|
|||||||
@@ -52,6 +52,29 @@ Setting `dynamicPartials: false`, LiquidJS will try to include the file named `f
|
|||||||
{% note warn Common Pitfall %}
|
{% note warn Common Pitfall %}
|
||||||
LiquidJS defaults this option to <code>true</code> to be compatible with shopify/liquid, but if you're from <a href="https://github.com/11ty/eleventy" target="_blank">eleventy</a> it's set to <code>false</code> by default (see <a href="https://www.11ty.dev/docs/languages/liquid/#quoted-include-paths" target="_blank">Quoted Include Paths</a>) which I believe is trying to be compatible with Jekyll.{% endnote %}
|
LiquidJS defaults this option to <code>true</code> to be compatible with shopify/liquid, but if you're from <a href="https://github.com/11ty/eleventy" target="_blank">eleventy</a> it's set to <code>false</code> by default (see <a href="https://www.11ty.dev/docs/languages/liquid/#quoted-include-paths" target="_blank">Quoted Include Paths</a>) which I believe is trying to be compatible with Jekyll.{% endnote %}
|
||||||
|
|
||||||
|
## Jekyll include
|
||||||
|
|
||||||
|
{% since %}v9.33.0{% endsince %}
|
||||||
|
|
||||||
|
[jekyllInclude][jekyllInclude] is used to enable Jekyll-like include syntax. Defaults to `false`, when set to `true`:
|
||||||
|
|
||||||
|
- Filename will be static: `dynamicPartials` now defaults to `false` (instead of `true`). And you can set `dynamicPartials` back to `true`.
|
||||||
|
- Use `=` instead of `:` to separate parameter key-values.
|
||||||
|
- Parameters are under `include` variable instead of current scope.
|
||||||
|
|
||||||
|
For example in the following template, `name.html` is not quoted, `header` and `"HEADER"` are separated by `=`, and the `header` parameter is referenced by `include.header`. More details please check out [include][include].
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
// entry template
|
||||||
|
{% include article.html header="HEADER" content="CONTENT" %}
|
||||||
|
|
||||||
|
// article.html
|
||||||
|
<article>
|
||||||
|
<header>{{include.header}}</header>
|
||||||
|
{{include.content}}
|
||||||
|
</article>
|
||||||
|
```
|
||||||
|
|
||||||
## extname
|
## extname
|
||||||
|
|
||||||
**extname** defines the default extension name to be appended into filenames if the filename has no extension name. Defaults to `''` which means it's disabled by default. By setting it to `.liquid`:
|
**extname** defines the default extension name to be appended into filenames if the filename has no extension name. Defaults to `''` which means it's disabled by default. By setting it to `.liquid`:
|
||||||
@@ -123,3 +146,4 @@ Parameter orders are ignored by default, for ea `{% for i in (1..8) reversed lim
|
|||||||
[layout]: ../tags/layout.html
|
[layout]: ../tags/layout.html
|
||||||
[wc]: ./whitespace-control.html
|
[wc]: ./whitespace-control.html
|
||||||
[intro]: ./intro-to-liquid.html
|
[intro]: ./intro-to-liquid.html
|
||||||
|
[jekyllInclude]: ../api/interfaces/liquid_options_.liquidoptions.html#Optional-jekyllInclude
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ title: Include
|
|||||||
|
|
||||||
## Jekyll include
|
## Jekyll include
|
||||||
|
|
||||||
|
{% since %}v9.33.0{% endsince %}
|
||||||
|
|
||||||
[jekyllInclude][jekyllInclude] 用来启用 Jekyll-like include 语法。默认为 `false`,当设置为 `true` 时:
|
[jekyllInclude][jekyllInclude] 用来启用 Jekyll-like include 语法。默认为 `false`,当设置为 `true` 时:
|
||||||
|
|
||||||
- 默认启用静态文件名:`dynamicPartials` 的默认值变为 `false`(而非 `true`)。但你也可以把它设置回 `true`。
|
- 默认启用静态文件名:`dynamicPartials` 的默认值变为 `false`(而非 `true`)。但你也可以把它设置回 `true`。
|
||||||
@@ -81,24 +83,28 @@ title: Include
|
|||||||
例如下面的模板:
|
例如下面的模板:
|
||||||
|
|
||||||
```liquid
|
```liquid
|
||||||
{% include name.html header="HEADER" content="CONTENT" %}
|
{% include article.html header="HEADER" content="CONTENT" %}
|
||||||
```
|
```
|
||||||
|
|
||||||
其中 `name.html` 的内容是:
|
其中 `article.html` 的内容是:
|
||||||
|
|
||||||
```liquid
|
```liquid
|
||||||
<header>{{include.header}}</header>
|
<article>
|
||||||
{{include.content}}
|
<header>{{include.header}}</header>
|
||||||
|
{{include.content}}
|
||||||
|
</article>
|
||||||
```
|
```
|
||||||
|
|
||||||
注意我们通过 `include.header` 引用第一个参数,而不是 `header`。输出如下:
|
注意我们通过 `include.header` 引用第一个参数,而不是 `header`。输出如下:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<header>HEADER</header>
|
<article>
|
||||||
CONTENT
|
<header>HEADER</header>
|
||||||
|
CONTENT
|
||||||
|
</article>
|
||||||
```
|
```
|
||||||
|
|
||||||
[extname]: ../../api/interfaces/liquid_options_.liquidoptions.html#Optional-extname
|
[extname]: ../../api/interfaces/liquid_options_.liquidoptions.html#Optional-extname
|
||||||
[root]: ../../api/interfaces/liquid_options_.liquidoptions.html#Optional-root
|
[root]: ../../api/interfaces/liquid_options_.liquidoptions.html#Optional-root
|
||||||
[dynamicPartials]: ../../api/interfaces/liquid_options_.liquidoptions.html#dynamicPartials
|
[dynamicPartials]: ../../api/interfaces/liquid_options_.liquidoptions.html#Optional-dynamicPartials
|
||||||
[jekyllInclude]: ../../api/interfaces/liquid_options_.liquidoptions.html#jekyllInclude
|
[jekyllInclude]: ../../api/interfaces/liquid_options_.liquidoptions.html#Optional-jekyllInclude
|
||||||
|
|||||||
@@ -47,9 +47,32 @@ const engine = new Liquid({
|
|||||||
{% liquid foo.html %}
|
{% liquid foo.html %}
|
||||||
```
|
```
|
||||||
|
|
||||||
{% note warn Common Pitfall %}
|
{% note warn 常见陷阱 %}
|
||||||
LiquidJS 把这个选项默认值设为 <code>true</code> 以兼容于 shopify/liquid,但如果你在使用 <a href="https://github.com/11ty/eleventy" target="_blank">eleventy</a> 它会设置默认值 <code>false</code> (参考 <a href="https://www.11ty.dev/docs/languages/liquid/#quoted-include-paths" target="_blank">Quoted Include Paths</a>)以兼容于 Jekyll。{% endnote %}
|
LiquidJS 把这个选项默认值设为 <code>true</code> 以兼容于 shopify/liquid,但如果你在使用 <a href="https://github.com/11ty/eleventy" target="_blank">eleventy</a> 它会设置默认值 <code>false</code> (参考 <a href="https://www.11ty.dev/docs/languages/liquid/#quoted-include-paths" target="_blank">Quoted Include Paths</a>)以兼容于 Jekyll。{% endnote %}
|
||||||
|
|
||||||
|
## Jekyll include
|
||||||
|
|
||||||
|
{% since %}v9.33.0{% endsince %}
|
||||||
|
|
||||||
|
[jekyllInclude][jekyllInclude] 用来启用 Jekyll-like include 语法。默认为 `false`,当设置为 `true` 时:
|
||||||
|
|
||||||
|
- 默认启用静态文件名:`dynamicPartials` 的默认值变为 `false`(而非 `true`)。但你也可以把它设置回 `true`。
|
||||||
|
- 参数的键和值之间由 `=` 分隔(本来是 `:`)。
|
||||||
|
- 参数放到了 `include` 变量下,而非当前作用域。
|
||||||
|
|
||||||
|
例如下面的模板中,`name.html` 没有带引号,`header` 和 `"HEADER"` 以 `=` 分隔,`header` 参数通过 `include.header` 来引用。更多详情请参考 [include][include]。
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
// entry template
|
||||||
|
{% include article.html header="HEADER" content="CONTENT" %}
|
||||||
|
|
||||||
|
// article.html
|
||||||
|
<article>
|
||||||
|
<header>{{include.header}}</header>
|
||||||
|
{{include.content}}
|
||||||
|
</article>
|
||||||
|
```
|
||||||
|
|
||||||
## extname
|
## extname
|
||||||
|
|
||||||
**extname** 定义了默认的文件后缀,当传入文件名不包含后缀时自动追加。默认值是 `''` 也就是说默认是禁用的。如果设置为 `.liquid`:
|
**extname** 定义了默认的文件后缀,当传入文件名不包含后缀时自动追加。默认值是 `''` 也就是说默认是禁用的。如果设置为 `.liquid`:
|
||||||
@@ -120,3 +143,4 @@ LiquidJS 把这个选项默认值设为 <code>true</code> 以兼容于 shopify/l
|
|||||||
[layout]: ../tags/layout.html
|
[layout]: ../tags/layout.html
|
||||||
[wc]: ./whitespace-control.html
|
[wc]: ./whitespace-control.html
|
||||||
[intro]: ./intro-to-liquid.html
|
[intro]: ./intro-to-liquid.html
|
||||||
|
[jekyllInclude]: ../api/interfaces/liquid_options_.liquidoptions.html#Optional-jekyllInclude
|
||||||
|
|||||||
Reference in New Issue
Block a user