2013-05-11 25 views
0

化身引导包括文件_includes/JB/setup什么是捕获一个液体变量,然后分配给零呢?

{% capture jbcache %} 
    <!-- 
    - Dynamically set liquid variables for working with URLs/paths 
    --> 
    {% if site.JB.setup.provider == "custom" %} 
    {% include custom/setup %} 
    {% else %} 
    {% if site.safe and site.JB.BASE_PATH and site.JB.BASE_PATH != '' %} 
     {% assign BASE_PATH = site.JB.BASE_PATH %} 
     {% assign HOME_PATH = site.JB.BASE_PATH %} 
    {% else %} 
     {% assign BASE_PATH = nil %} 
     {% assign HOME_PATH = "/" %} 
    {% endif %} 

    {% if site.JB.ASSET_PATH %} 
     {% assign ASSET_PATH = site.JB.ASSET_PATH %} 
    {% else %} 
     {% capture ASSET_PATH %}{{ BASE_PATH }}/assets/themes/{{ page.theme.name }}{% endcapture %} 
    {% endif %} 
    {% endif %} 
{% endcapture %}{% assign jbcache = nil %} 

我明白,这1)捕获文本作为一个变量然后2)分配给它为nil立即,有效地把它扔掉。那么这是做什么的?

回答

2

因为你想渲染的副作用,但不想渲染的输出。如果不需要捕获,则输出呈现的内容。但是你实际上并不需要输出,所以当你完成后就把它扔掉。这是一个轻微的黑客攻击。

所以如果你想计算而不输出结果,捕获变量是一个合理的事情。 “然后分配给零”破解是一种说法,我们对渲染计算的副作用感兴趣,而不是输出。那些其他的assign仍然存在即使在变量被抛出时仍然存在的效果。

{%include custom/setup %}的输出同样会被丢弃,但其副作用可能很重要。

相关问题