Is it possible to create a new ejs file based on the previous file?

Viewed 12

I am trying to create a navbar for my site, and I wonder how to have ejs files automatically have code added from another ejs file. In flask in python it is done on the {% block title%} principle and in another file it is done {% extends 'base.html'%} and then {% block title%} This is title {% endblock%}
Does anyone know if this is possible in javascript?
I am using javascript express and the ejs rendering engine.

1 Answers

I think you need to use include statement, see https://ejs.co/#docs the "includes" part.

You can include (as if import) an ejs template with

<%- include('mifile', {mykey: mydata, mykey2: myotherdata}); %>

The only thing i don't like its the passing parameters explicitly from one template to another, that can be made many times at many levels (an include inside an included template).

I don't know if is there a base/parent template thing like in jinja2 (inheritance), I think not.

Related