Skip to navigation Skip to main content
11ty Logo Sustainability Fundraising
Eleventy
Eleventy Documentation
Stable
2.0.1
Canary
3.0.0-alpha.16
Toggle Menu
Eleventy 1.93s
Next.js 70.65s

Template Languages

重置模板引擎 Jump to heading

有以下几种方式来告诉 Eleventy 如何处理文件:

  1. The file extension (importantly, this is also used to find files to process).
  2. Configuration options:
    • markdownTemplateEngine: The default global template engine to pre-process markdown files. Use false to avoid pre-processing and only transform markdown.
    • htmlTemplateEngine: The default global template engine to pre-process HTML files. Use false to avoid pre-processing and passthrough copy the content (HTML is not transformed, so technically this could be any plaintext).
  3. templateEngineOverride in the template’s front matter. Should be one templating engine (liquid) or markdown paired with another templating engine (liquid,md). See examples below.

templateEngineOverride 示例 Jump to heading

改变文件对应的模板引擎 Jump to heading

如果你的文件名是 example.liquid,经过以下设置,其不再用 liquid 引擎处理,而是用 Nunjucks(njk)模板引擎处理:

Filename example.liquid
---
templateEngineOverride: njk
---

特殊情况:为 Markdown 配对一个模板引擎 Jump to heading

请记住,默认情况下,Markdown 文件会被预先用 markdownTemplateEngine 参数所设置的模板引擎进行预处理。因此,为 markdown 文件设置 templateEngineOverride 参数时,务必列出你所要使用的每个模板引擎(也就是说最后一个必须是 md)。

例如,你可能希望先用 Nunjucks(njk )预处理,然后作为 markdown(md) 再次处理。只有 Markdown 支持这种方式,其他模板都不可以以这种方式组合。Markdown 是这里的唯一例外。任何其它组合都会报错。

只作为 Markdown 处理,不做任何其他预处理
---
templateEngineOverride: md
---
先用 Nunjucks 预处理,再做为 Markdown 处理
---
templateEngineOverride: njk,md
---
什么也不用(即,不做转换)

赋予 false 值时,只复制模板内容而不做任何转换。

---
templateEngineOverride: false
---

Template Languages: