且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Node.js,Express,EJS - 导航中当前页面上的活动类

更新时间:2022-04-22 23:06:19

您可以在 res.render中包含 page_name:'about' 数据,然后在模板中,例如:

You could include a page_name: 'about' in the res.render data and then in the template something like:

<li <% if (page_name === 'about') { %>class="current" <% } %> ><a href="/about">About</a></li>

我没有测试语法,但这就是要点。

I didn't test the syntax, but that's the gist.