Hexo: Helpers not available when using hexo.render

Created on 4 Jul 2015  路  6Comments  路  Source: hexojs/hexo

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?

question theme

Most helpful comment

All 6 comments

@cyberwombat Helpers works for themes, such as .ejs files.

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...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SukkaW picture SukkaW  路  25Comments

curbengh picture curbengh  路  24Comments

icepy picture icepy  路  34Comments

wych42 picture wych42  路  23Comments

tomap picture tomap  路  21Comments