How to use helpers in Hexo source files?

你离开我真会死。 提交于 2019-12-11 14:00:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!