主题

hexo.theme 继承自 盒子,还保存模板。

¥hexo.theme inherits from Box, and also saves templates.

获取视图

¥Get a View

hexo.theme.getView(path);

设置视图

¥Set a View

hexo.theme.setView(path, data);

删除视图

¥Remove a View

hexo.theme.removeView(path);

视图

¥View

视图有两种方法:renderrenderSync。这两种方法相同,但前者是异步的,后者是同步的。因此,为了简单起见,我们在这里只讨论 render

¥Views have two methods: render and renderSync. 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 方法,它将尝试使用相应的渲染器处理模板并加载 helpers。当渲染完成时,它会尝试查找布局是否存在。如果 layoutfalse 或不存在,则直接返回结果。

¥You can pass options to the render method and it will try to process the template with the corresponding renderer and load the helpers. 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.