在模板本身内使用ejs模板名称

时间:2016-10-28 14:30:45

标签: javascript html node.js templates ejs

我正在使用ejs模板在不同的div中生成一些内容。

让我们说它看起来像这样:

account:
    setttings:
         default_tax_rate: "-somekey"
    tax_rates:
         "-somekey":
              "name":"5.5"
         "-someotherkey"
               "anothername":"4.5"

并且在每个模板中,我想知道我自动使用的模板。例如,假设我在“templatei.ejs”文件中(其中i是第i个模板的索引)。现在有什么方法可以让我知道里面的模板名称吗?

这是每个模板文件的外观:

<% include test1 %>

<% include test2 %>

<% include test3 %>

this.fileName()不起作用它只是为了表达我的意思。 我实际上想为每个div添加一个单独页面的链接。

  

我不使用javascript生成网址的原因是我想要的   爬虫找到它,我不认为爬虫会刮掉页面   在js改变之后。

1 个答案:

答案 0 :(得分:0)

在include语句中发送文件名(您要呈现的文件)。

<%- include('test1', {filename: 'data'}) %>

在test1 ejs中

<div>
<h2>header info</h2>
<p>some text comes here</p>
<a href="/<% filename %>"><a>
</div>