0

我有以下布局,使用 jekyll 3.7.3;

declare A = apple

include file.html > declare A = orange

print A => orange

我很困惑如何在jekyll 的文档A=orange中泄露到父布局,说变量通过液体标签进行评估。这也适用于吗?正如在github 对话和此对话中所说的那样,子布局覆盖父布局的位置没有任何意义。layoutinclude

所以我的问题是这种继承是如何工作的?

根据我对继承的理解,应该有一些控制子变量如何覆盖父变量。从文档来看,我相信是通过变量layout. 那么这应该是这样的;

declare A = apple 

include file.html > declare layout.A = orange

print A => apple

其他情况是;

声明 A = 苹果

包括 file.html > 打印 A => 苹果

声明 A = 橙色

打印 A => 橙色

如果子include继承了值而没有明确告诉它,那么在包含中有一个参数有什么意义。

也有泄漏变量进入include孩子,这意味着孩子include不再为了特殊情况而被隔离,就像这里所说的那样

4

1 回答 1

2

包含和布局不一样。

在生成网站时,Jekyll 会按照特定的顺序做很多事情。

  • 读取页面数据
  • 渲染液体
    • 使必要的includes
    • 计算液体标签和过滤器
  • 如果文档是降价的,则呈现 html
  • 渲染布局

当它呈现液体时:

=== page.html
include other.html

print a
assign: a = apple
print a

include other.html
=== end page.html

变成一堆这样处理的代码:

=== page.html
  ====== other.html
  print a ------> nil
  assign: a = orange
  print a ------> orange
  ====== end other.html
print a ------> orange
assign: a = apple
print a ------> apple
  ====== other.html
  print a ------> apple
  assign: a = orange
  print a ------> orange
  ====== end other.html
=== end page.html

液体标签完全按照它们在代码中出现的顺序执行,并且变量(在页面正文中分配的局部变量,而不是冻结且无法更改的前面的那个)是全局的,可以从页面或任何子项覆盖.

在此之后,如有必要,它会呈现 HTML,并{{ content }}在布局中“吐出”页面,这些页面对页面的局部变量一无所知,只能看到在前面定义的页面变量。

于 2018-03-16T14:01:10.157 回答