简体   繁体   中英

Include non ejs files in ejs template engine

Is it posible to add files that dont have the .ejs ending when using the ejs template engine with node.js and express?

I want to put shaders in seperate files with .glsl ending for example. Than I want to include them like this:

<% include /shaders/example.vertex.glsl %>

If I use example.vertex.glsl.ejs it works, but than syntax highlighting for shaders is not working anymore...

I am actually not bound to ejs. Any other express templating engine this would work in is fine. I just used ejs because I worked with it already a little bit beforehand.

You can do this as long as you tell the express what engine should be used to process the extension with app.engine(ext, callback) .

Set the following before your routes somewhere:

app.engine('glsl', require('ejs').renderFile);

Then your includes such as <% include /shaders/example.vertex.glsl %> will work fine. These are processed in the same way as ejs files then, so as well as the include working as you describe, you can also put inline <%=variableFromNode%> type stuff in the included glsl files and it will process that too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM