主题

hexo.theme 除了继承 Box 外,还具有存储模板的功能。

Get a View

hexo.theme.getView(path);

Set a View

hexo.theme.setView(path, data);

Remove a View

hexo.theme.removeView(path);

View

模板本身有两个方法可供使用:renderrenderSync。 These two methods are identical, but the former is asynchronous and the latter is synchronous. So for the sake of simplicity, we will only discuss render here.

var view = hexo.theme.getView("layout.swig");

view.render({ foo: 1, bar: 2 }).then(function (result) {
// ...
});

您可以以向 render 方法传入对象作为参数,render 方法会先使用对应的渲染引擎进行解析,并加载 辅助函数。 When rendering is complete, it will try to find whether a layout exists. If layout is false or if it doesn’t exist, the result will be returned directly.