Layout variables
Layouts and includes are EJS templates that run in Node.js at build time. Besides the data passed to an include, every template can use these variables.
page
The page being rendered:
url- the page's URL, such as/guide/index.html.content- the HTML compiled from the page's Markdown file.sourcePath- the page's Markdown file, from the project's folder, such asdocs/guide/index.md. The default theme makes its link to edit the page from it.- every front matter value, such as
page.title. commentsandcommentsSourcePath- on API pages, the parsed JSDoc comments and the path of the file they come from.
html
<h1><%= page.title %></h1>
<%- page.content %>pages
Every page of the site, each as an object with a url.
html
<ul>
<% for (const { url } of pages) { %>
<li><a href="<%= url %>"><%= url %></a></li>
<% } %>
</ul>appSettings
The appSettings object from the configuration file. appSettings.name defaults to
the name in your package.json.
html
<title><%= page.title %> | <%= appSettings.name %></title>configuration
The complete configuration, with defaults filled in.
importModule
Imports an ES module. Use it with await, because templates cannot use the
import statement. Relative paths are resolved from the folder of the layout
being rendered, also when you call it from an include.
html
<% const { sidebar } = await importModule('../sidebar.js'); %>Its name in 0.3.0-preview4, _import, still works, with a warning.
require, __filename and __dirname
require- loads a CommonJS module or a JSON file. Relative paths are resolved from the layout's folder.__filename- the absolute path of the layout being rendered.__dirname- the absolute path of the layout's folder.
html
<% const versions = require('../versions.json'); %>