从多个子模板继承模板
template inheritance from multiple sub-templates
本文关键字:继承 更新时间:2023-09-26
所以我有一个网站,它的结构由各种模板组成:
- index //the html skeleton, with script tags and css links
- header //the header of the page
- topnavigation //contains the main nav with the menu
- content //this is where the dynamic content will be changed for different pages
- footer //the footer
现在,我知道集成它的唯一方法是:
res.render(content);
content -> inherits footer
footer -> inherits topnavigation
topnavigation-> inherits header
header -> inherits index
我认为如果我能有这样的东西,它会更实用和易于维护:
res.render(content);
content -> inherits dochead
index -> includes header + topnnavigation + footer
- 我错了吗?
- 如果我是对的,我该怎么做?
谢谢
典型的extends
设置更像是这样的:(对于一个工作示例,您可以在此处查看Swig文档如何设置其布局:https://github.com/paularmstrong/swig/tree/master/docs/layouts)
-
skeleton.html
带有块的 html 框架:-
{% block html %}
-
{% block css %}
-
{% block js %}
-
{% block body %}
-
-
base.html
扩展了skeleton.html
,带有块/子块的基本布局:-
{% block body %}
-
{% block header %}
包括一些默认标头内容。-
{% block nav %}
包括主要导航内容。
-
-
{% block content %}
空 -
{% block footer %}
包括版权等。
-
-
-
index.html
扩展base.html
-
{% block nav %}
(可能用于导航的内容,否则只需base.html
呈现其导航内容 - 您还将根据需要覆盖此处
base.html
中设置的任何其他块。如果您发现自己需要对模板进行更多控制,请考虑创建另一个扩展base.html
的子布局,然后index.html
扩展该布局。
-
相关文章:
- 从控制器继承了隔离的作用域以生成可重用的指令
- 两个指令创建新的继承的和隔离的作用域-元素得到哪个
- 当使用控制器作为语法时,如何从父指令继承属性
- 以jquery方式继承Javascript
- JavaScript对象不是从原型链继承的
- 使用Object.create()的角度服务继承
- 数据与Javascript中的继承冲突
- JavaScript对象继承问题
- Javascript嵌套函数属性继承
- 为什么不't htmlCollection从数组继承
- 继承的属性检查
- 没有预定义宽度的固定元素最初放在引导容器中,不会从父元素继承宽度
- 如何使用原型继承编写一个整洁灵活的复杂javascript应用程序
- 使用技巧在javascript中强制执行私有继承
- $emit,$broadcast,原型继承
- 如何检查DOM节点是否继承自构造函数
- Javascript多重继承模式
- 玉中继承模板的修改
- Angular中的作用域继承$broadcast
- 关于Javascript继承,我可以'我不明白