Hexo: Can I access site.data when in a helper?

Created on 19 Jan 2018  ·  3Comments  ·  Source: hexojs/hexo

Say I have /scripts/blah.js:

/* global hexo */

hexo.extend.helper.register('someMethod', (arg1) => {
  // can I access site.data here?
})

Is there a way to access site.data in a script file, in particular within a helper method? Or do I need to pass site.data into the helper as an argument?

question stale

Most helpful comment

Helpers are called with the hexo context as this, so it would be:

hexo.extend.helper.register('someMethod', function (arg1) {
  console.log(this.site.data)
})

All 3 comments

a similar question here: https://github.com/hexojs/hexo/issues/3025
I didn't find some useful information about this in helper section of the document.

Helpers are called with the hexo context as this, so it would be:

hexo.extend.helper.register('someMethod', function (arg1) {
  console.log(this.site.data)
})

This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings