翡翠之间的区别与封闭 [英] Difference between include and block in Jade
问题描述
在创建Jade模板时,块和使用include之间有什么区别?你什么时候使用另一个?
块是占位符。其内容来自另一个玉器文件。
包含也是占位符。它的内容也来自另一个玉器文件。
到目前为止,两者都是平等的。
但是: p>
include嵌入一个完整的文件。包含文件定义要包括哪个文件。因此,包含对于外部部件(如页脚或标题)是很好的,它们总是以相同的方式加载。
块仅在顶部文件中定义占位符。包含哪些内容不是由此文件定义的,而是由子文件定义的。所以,控制所包含的内容正在被逆转。
有一个include,A说:Import B.
B有一个块,这里是内容对于占位符,请使用文件A及其占位符填写我的内容。
包含意味着自上而下,块意味着自下而上。
$另外,一个文件可能包含几个块。何时使用什么:
- 通常在具有块的主页面中定义站点的总体布局。
- 单个页面包含每个单独文件的内容,参考主文件并填写其块。
- 正在使用包括设置主或页面中的子视图。
有帮助吗?
What is the the difference between blocks and using include when you are creating Jade templates? When do you use one over the other?
A block is a placeholder. Its content comes from another jade file. An include is a placeholder, too. Its content also comes from another jade file.
So far, both are equal.
But:
include embeds a complete file. The including file defines which file is being included. Hence include is fine for outsourcing parts such as a footer or a header, which are always loaded the same way.
A block just defines a placeholder in the top file. Which content is included is not defined by this file, but by a sub-file. So, control over what is included is being reversed.
With an include, A says: Import B. With a block, B says: Here is content for a placeholder, and please use file A and its placeholders to fill in my content.
include means top-down, blocks mean bottom-up.
Additionally, one file may include several blocks.
When to use what:
- It's common to define the overall layout of a site in a master page with blocks.
- The single pages contain the content for each individual file, reference the master file and fill its blocks.
- Subviews in either the master or the page are being set up using includes.
Does that help?
这篇关于翡翠之间的区别与封闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!