提问者:小点点

杰基尔遗产


我有以下布局,带有 jekyll 3.7.3;

declare A = apple

include file.html > declare A = orange

print A => orange

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

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

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

declare A = apple 

include file.html > declare layout.A = orange

print A => apple

另一种情况是;

声明 A = 苹果

包含文件.html

声明 A = 橙色

打印 A =

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

此外,将泄漏变量泄漏到包含子项中,这意味着子项包含不再出于特殊情况的目的而被隔离,就像这里所说的那样


共1个答案

匿名用户

包含和布局不同。

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

  • 读取页面的数据
  • 渲染液体
    • 使必要的包括
    • 计算液体标签和过滤器

    当它呈现液体时:

    === 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,并在布局中“吐槽”页面的 {{ 内容 }},该布局对页面的局部变量一无所知,只能看到在前面定义的页面变量。