问题描述:

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.

相关阅读:
Top