ejs 'partial is not defined'

后端 未结 2 1602
太阳男子
太阳男子 2020-12-14 16:15

Okay I have a mostly static homepage but I wanted to have partial views that for navigation, footer ect. I\'m using ejs and it looks like this:

my controller: home.j

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 17:01

    As @Pickels said, Partial was removed in 3.x. However, the most recent version of EJS provides a mechanism for including "partials", called "include":

    https://github.com/visionmedia/ejs#includes

    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.

    The following will work as a replacement for your old partial() function. You'll need to make tweaks elsewhere to support Express 3.x completely, but for the most part this seems to work well (better actually - less code and more performant).

    <% include nav.ejs %> 
    

提交回复
热议问题