I have a console plugin which calls hexo.load() then proceed to do a custom render of a post. All works fine except for any helper I have added. Seems like these either get loaded too late or not at all when using the render API. I've also tried a standalone script that creates a new instance of Hexo and inits it per API docs with same result. How does one create a console script that can render with helpers?
@cyberwombat Helpers works for themes, such as .ejs files.
Do helpers only work for .ejs and not for Swig/Nunjucks?
I also need more info about this.
In a custom generator I use the render API:
hexo.extend.generator.register('gen1', function (locals) {
return {
path: 'gen1.html',
data: hexo.render.renderSync({path: 'template.ejs'}, locals); // <--- ERROR here
};
}
template.ejs
<p> Text <%-partial('partialTemplate') %>
The code throws error because partial is not defined.
It seems helpers aren't loaded or unavailable.
Any thoughts?
@Xuanwo so is not possible to load partials from files inside the /source folder?
@cesarvarela I don't think so.
Commenting here because I have the exact same issue as @giuseppelt
Trying to use hexo.render.renderSync and my template file won't run because has a partial() inside of it. I get the error partial is not defined.
Is there no way around this? It seemed intuitive to me that hexo.render would render just like all my other templates...
Most helpful comment
Do helpers only work for .ejs and not for Swig/Nunjucks?
https://bitbucket.org/morrisallison/hexo-renderer-nunjucks/issues/1/question-how-do-i-use-hexo-helpers