EJS
模板语言:
- Ant Design
*.tsx - Astro
*.astro - Bootstrap
*.html - Chakra UI
*.tsx - Docsify
*.md - Docusaurus
*.mdx - ESBuild
*.js - Eleventy
*.11ty.js - Gatsby
*.js - GitBook
*.md - Gridsome
*.vue - Hexo
*.ejs - Hugo
*.html - Jekyll
*.html - Mantine
*.tsx - Material-UI
*.js - MkDocs
*.md - Next.js
*.js - Nuxt.js
*.vue - Parcel
*.html - Remix
*.tsx - Rollup
*.js - Storybook
*.stories.js - Sphinx
*.rst - SvelteKit
*.svelte - SWC
*.ts - Tailwind CSS
*.css - Turbopack
*.ts - Vite
*.ts - VitePress
*.md - VuePress
*.vue - Webpack
*.js - 自定义框架
*.*
| Eleventy 简称 | 文件扩展名 | npm 包 |
|---|---|---|
ejs |
.ejs |
ejs |
| Eleventy 或插件版本 | ejs 版本 |
|---|---|
@11ty/eleventy@0.x |
ejs@2.x |
@11ty/eleventy@1.x |
ejs@3.x |
@11ty/eleventy@2.x |
ejs@3.x |
@11ty/eleventy@3.x 及更新版本 |
N/A |
@11ty/eleventy-plugin-ejs@1.x |
ejs@3.x |
您可以覆盖 .ejs 文件的模板引擎。更多信息请阅读更改模板的渲染引擎。
安装
ejs 模板语言在 v3 中已从 Eleventy 核心中移出,现在需要插件安装。
从 npm 安装:
npm install @11ty/eleventy-plugin-ejs
添加到您的配置文件:
eleventy.config.js
import ejsPlugin from "@11ty/eleventy-plugin-ejs";
export default function (eleventyConfig) {
eleventyConfig.addPlugin(ejsPlugin);
}
const ejsPlugin = require("@11ty/eleventy-plugin-ejs");
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(ejsPlugin);
}
使用更多 ejs 选项(完整选项列表):
eleventy.config.js
import ejs from "ejs";
import ejsPlugin from "@11ty/eleventy-plugin-ejs";
export default function (eleventyConfig) {
eleventyConfig.addPlugin(ejsPlugin, {
async: false, // 默认
// 使用 <? ?> 而不是 <% %>
delimiter: "?",
// 覆盖 `ejs` 库实例
eleventyLibraryOverride: ejs,
});
}
const ejs = require("ejs");
const ejsPlugin = require("@11ty/eleventy-plugin-ejs");
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(ejsPlugin, {
async: false, // 默认
// 使用 <? ?> 而不是 <% %>
delimiter: "?",
// 覆盖 `ejs` 库实例
eleventyLibraryOverride: ejs,
});
}
支持的功能
| 功能 | 语法 |
|---|---|
| ✅ 包含(预处理器指令) | <% include /user/show %> 查找 _includes/user/show.ejs(开头的斜杠很重要)。不处理 include 文件中的前置内容。 |
| ✅ 包含(相对路径,预处理器指令) | ejs 中的相对路径可以省略开头的斜杠 / 或使用 ./ 来使用模板的目录,或使用 ../ 来使用模板的父目录:<% include 'user/show' %> 或 <% include './user/show' %> 从模板的当前目录查找 ./user/show.ejs。不处理 include 文件中的前置内容。 |
| ✅ 包含(传入数据) | <%- include('/user/show', {user: 'Ava'}) %> 查找 _includes/user/show.ejs。不处理 include 文件中的前置内容。 |
| ✅ 包含(相对路径,传入数据) | ejs 中的相对路径可以省略开头的斜杠 / 或使用 ./ 来使用模板的目录,或使用 ../ 来使用模板的父目录:<%- include('user/show', {user: 'Ava'}) %> 或 <%- include('./user/show', {user: 'Ava'}) %> 从模板的当前目录查找 ./user/show.ejs。不处理 include 文件中的前置内容。 |