How to list files in folder from a ejs file #5226
-
I would like to add all images to a template, by listing the files from a folder. I tried
But I receive:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Currently, all You can, however, create a custom hexo helper plugin to inject variables. Here is an example: https://github.com/SukkaW/hexo-theme-suka/blob/1d457ac9fbad421d2e6b9853ae1cb3dfc5cadf05/scripts/index.js#L17 |
Beta Was this translation helpful? Give feedback.
Currently, all
ejs
files are executed in their own VM and context, andejs
can not have access to any Node.js built-in globals at all.You can, however, create a custom hexo helper plugin to inject variables. Here is an example:
https://github.com/SukkaW/hexo-theme-suka/blob/1d457ac9fbad421d2e6b9853ae1cb3dfc5cadf05/scripts/index.js#L17
https://github.com/SukkaW/hexo-theme-suka/blob/master/includes/helpers/qrcode.js
https://github.com/SukkaW/hexo-theme-suka/blob/1d457ac9fbad421d2e6b9853ae1cb3dfc5cadf05/layout/_partial/menu/index-share.ejs#L57