2013-05-11 83 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 %}的輸出同樣會被丟棄,但其副作用可能很重要。

相關問題