include 模板标签
实例
在模板中包含一个模板:
<!DOCTYPE html><html><body>{% include mymenu.html %}<h1>Welcome</h1><p>This is my webpage</p></body></html>
定义和用法
include 标签让您可以包含来自另一个模板的内容。
将 include 标记放在您希望内容显示的位置。
当您在许多页面上有相同的内容时很有用。
还可以使用 with 关键字将变量发送到模板中。
实例
如果 include 文件如下所示:
模板可以像这样将变量值发送到 include 中:
<!DOCTYPE html><html><body>{% include mymenu.html with me="ALEXANDER" sponsor="CANKAOSHOUCE" %}<h1>Welcome</h1><p>This is my webpage</p></body></html>
语法
{% include template %}
或者
{% include template with key=value%}
参数
| 值 | 描述 |
|---|---|
| template | 必填。模板的文件名。字符串或变量。 |
| key=value | 可选。要发送到包含文件的变量名和值。与 with 关键字一起使用。可以有任意多个键/值对。 |