如何在Hexo源文件中使用助手? [英] How to use helpers in Hexo source files?

查看:93
本文介绍了如何在Hexo源文件中使用助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于页面source/about/index.ejs.在此页面中,我想在ejs标记内使用image_tag() helper 辅助功能.但是,如果这样做,则会出现错误image_tag is not defined,并且对于其他任何辅助函数也相同.

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.

我认为这意味着仅在主题目录中呈现source中的文件时,不会加载帮助程序.似乎我也无法将这种类型的页面放置在them目录中,而无法使用模板进行呈现.有没有办法可以使用助手来渲染源文件?如果不是,我为什么不能,或者为什么这是个坏主意?

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?

推荐答案

Hexo Helpers在源文件中不可访问.您必须在视图中使用它.
1.在layout/about.ejs
中创建视图 2.使用助手标签在其中添加代码
3.使用hexo new page "about"
创建一个新页面 3.在source/about/index.md文件的开头添加layout:"about".

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.

这篇关于如何在Hexo源文件中使用助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆