In EJS template engine, how do I “include” a footer?

前端 未结 6 1444
萌比男神i
萌比男神i 2020-12-09 01:42

Let\'s say I saved a snipplet of a footer. How do I \"include\" that in my current template?

6条回答
  •  攒了一身酷
    2020-12-09 02:11

    EJS makes it very simple to use includes. Here is how it is described in the EJS README:

    Includes are relative to the template with the include statement, for example if you have "./views/users.ejs" and "./views/user/show.ejs" you would use <% include user/show %>. The included file(s) are literally included into the template, no IO is performed after compilation, thus local variables are available to these included templates.

      <% users.forEach(function(user){ %> <% include user/show %> <% }) %>

    So, in your case, if the footer resides in the same directory as the file you want to include it in, you would simply add <% include footer %> to your file.

提交回复
热议问题