问题
I have an about page called source/about/index.ejs
. In this page, I'd like to use the image_tag()
helper within ejs tags, and other helper functions. However, if I do, I get the error image_tag is not defined
, and the same for any other helper function.
I assume this means helpers are not loaded when rendering files in the source
, only in the theme directory. It also seems that I can't put this type of page in the them directory and have it render with a template. Is there a way I can use helpers in rendering source files? If not, why can't I, or why would it be a bad idea?
回答1:
Hexo Helpers are not reachable in source files. You have to use it in views.
1. Create a view in layout/about.ejs
2. Add your code in it with helpers tag
3. Create a new page with hexo new page "about"
3. Add layout:"about"
in the front-matter of source/about/index.md
file.
回答2:
The best solution to this is tag plugins.
You'll have to rewrite the helpers you want as tag plugins, but after that they're usable in source files. Check out node_modules/hexo/lib/plugins/tag
for examples.
来源:https://stackoverflow.com/questions/33729493/how-to-use-helpers-in-hexo-source-files