我使用ejs模板在不同的div中生成一些内容。
假设它看起来有点像这样:
<% include test1 %>
<% include test2 %>
<% include test3 %>
在每一个模板中,我想知道我自动地在哪个模板中。例如,假设我在"templatei.ejs“文件中(其中我是ith模板的索引)。现在有什么方法让我知道它里面的模板名吗?
每个模板文件的外观如下:
<div>
<h2>header info</h2>
<p>some text comes here</p>
<a href="/<% this.fileName() %>">now I want this url to be a link to a seperate page that only loads one template<a>
</div>
this.fileName()将不起作用--这只是为了表达我的意思。实际上,我想为我的每个div添加一个链接到单独的页面。
我之所以不使用javascript来生成urls,是因为我希望爬虫能够找到它,而且我认为爬虫不会在js更改后刮掉页面。
发布于 2016-11-10 09:03:02
在include语句中发送文件名(要呈现的文件名)。
<%- include('test1', {filename: 'data'}) %>
内部test1 ejs
<div>
<h2>header info</h2>
<p>some text comes here</p>
<a href="/<% filename %>"><a>
</div>
https://stackoverflow.com/questions/40307352
复制相似问题