跳转到导航 跳转到主要内容
CNB版本
社区版
cnb.cool
国外版
cnb.build
2025/12/14

Mustache

本页大纲
Eleventy 简称 文件扩展名 npm 包
mustache .mustache mustache
Eleventy 或插件版本 mustache 版本
@11ty/eleventy@0.x mustache@2.x
@11ty/eleventy@1.x mustache@4.x
@11ty/eleventy@2.x mustache@4.x
@11ty/eleventy@3.x 及更新版本 N/A
@11ty/eleventy-plugin-mustache@1.x mustache@4.x

您可以覆盖 .mustache 文件的模板引擎。更多信息请阅读更改模板的渲染引擎

安装

.mustache 模板语言在 v3 中已从 Eleventy 核心中移出,现在需要插件安装。

npm install @11ty/eleventy-plugin-mustache

添加到您的配置文件:

eleventy.config.js
import mustachePlugin from "@11ty/eleventy-plugin-mustache";

export default function (eleventyConfig) {
eleventyConfig.addPlugin(mustachePlugin);
}
const mustachePlugin = require("@11ty/eleventy-plugin-mustache");

module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(mustachePlugin);
}

使用更多选项:

eleventy.config.js
import mustache from "mustache";
import mustachePlugin from "@11ty/eleventy-plugin-mustache";

export default function (eleventyConfig) {
eleventyConfig.addPlugin(mustachePlugin, {
// 覆盖 `mustache` 库实例
eleventyLibraryOverride: mustache,
});
}
const mustache = require("mustache");
const mustachePlugin = require("@11ty/eleventy-plugin-mustache");

module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(mustachePlugin, {
// 覆盖 `mustache` 库实例
eleventyLibraryOverride: mustache,
});
}

支持的功能

功能 语法
✅ 部分模板 {{> user}} 查找 _includes/user.mustache。不处理 include 文件中的前置内容。
🚫 部分模板(相对路径) 尚不支持{{> ./user}} 在模板当前目录中查找 user.mustache

其他页面在 Template Languages