EJS-包含时传递变量 [英] EJS - pass variable when include
本文介绍了EJS-包含时传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在后端与nodejs一起使用ejs。
我想在包含时传递变量。当包含标题时,传递页面标题。
I'm using ejs in backend with nodejs. I'd like to pass variable when include. When include the header, pass the page title.
index.ejs:
index.ejs:
<% include header %>
<body> . . . </body>
<% include footer%>
header.ejs:
header.ejs:
<html lang="en">
<head>
<title><%- my_tytle %></title>
</head>
footer.ejs:
footer.ejs:
</html>
如何在include命令中传递 my_title
?
How to pass my_title
in the include command?
推荐答案
您可以在include语句内传递对象
You can pass the object inside the include statement
<%-include( header,{title: your_title})%>
这篇关于EJS-包含时传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文