2012-11-11 65 views
3

我終於給Stash(EE 2.5.3上的版本2.3.5)一個項目去看看它是否像每個人都說的那麼好。使用隱藏的空白輸出

我已經按照該文檔爲盡我所能,併成立了藏匿在頁面的標題如下:

{exp:channel:entries channel="homepage" limit="1" dynamic="no"} 
{exp:stash:set_list name="homepage"} 
    {stash:cf_homepage_main_intro}{cf_homepage_main_intro}{/stash:cf_homepage_main_intro} 
    {stash:cf_homepage_strapline}{cf_homepage_strapline}{/stash:cf_homepage_strapline} 

    {cf_homepage_contact_info} 
     {stash:mx_pinterest}{mx_pinterest}{/stash:mx_pinterest} 
     {stash:mx_facebook}{mx_facebook}{/stash:mx_facebook} 
     {stash:mx_twitter}{mx_twitter}{/stash:mx_twitter} 
     {stash:mx_tel}{mx_tel}{/stash:mx_tel} 
     {stash:mx_email}{mx_email}{/stash:mx_email} 
     {stash:mx_address}{mx_address}{/stash:mx_address} 
    {/cf_homepage_contact_info} 
{/exp:stash:set_list} 
{/exp:channel:entries} 

然後在我的模板的其餘部分,我試圖請撥打以下值:

{exp:stash:homepage:mx_tel} 

但是,我什麼也沒得到。

如果我輸出的字段名直接它們工作得很好,我也打開調試,我可以看到在其中藏匿設定值的點,所有看起來不錯,但調試器報告如下:

*隱藏:RETRIEVED主頁:mx_email與價值*

我有點不知所措從哪裏去...這裏有沒有人有任何指針?

感謝,

卡爾

+0

好的 - 我現在使用{exp:stash:set}和{exp:stash:get}來調整它,但仍然沒有運氣。 {exp:stash:set name =「cf_homepage_main_intro」} {cf_homepage_main_intro} {/ exp:stash:set}然後{exp:stash:cf_homepage_main_intro} – madebyhippo

回答

5

啊!我在你的問題中看到你正試圖從同一個模板中調用變量。所以你遇到了解析順序問題。您需要將process="end"參數添加到您的exp:stash:get_listexp:stash:get標籤。並閱讀我的article about template partials

3

嗯,我想也許你有語法錯誤的。嘗試:

{exp:stash:get_list name="homepage"} 
    Telephone: {mx_tel} 
{/exp:stash:get_list} 

另外,如果你只是檢索一個項目,我會跳過使用set_list,只是使用設置爲單獨的變量。這兩件事都有效,但我認爲它更直觀..?

+0

我按照https://github.com/croxton/ Stash/tree/dev展示瞭如何做到這一點。 – madebyhippo

+0

我同意這個答案。 – Natetronn

+1

就語法而言,上述答案是正確的,即使在開發中也是如此。快捷方式語法不適用於列表。不過,繼續使用set_list不失爲一個好主意。它允許你保持乾燥的東西。 – adrienne

2

{EXP:藏匿:set_list名稱= 「主頁」} {EXP:信道:條目信道= 「主頁」 極限= 「1」 動態= 「否」}

不要緊即藏匿是內部循環,就像在解析順序中的東西一樣,不會先存儲?

+0

兩種方式沒有任何區別:( – madebyhippo

+0

這應該是對問題的評論,而不是單獨的「答案」。 – adrienne

3

使用set_list,append_list和prepend_list時,您需要使用Stash的get_list標記對。

你正在使用的是一個Stash快捷方式,它與stash相同:雖然不同於stash:get_list根據文檔。

使用get_list:

https://github.com/croxton/Stash/tree/dev#expstashget_list-tag-pair

拿不到快捷:

https://github.com/croxton/Stash/tree/dev#shortcut-tags(用於設置/獲取)

此外,您正在使用的快捷方式實際上是利用的context

{exp:stash:your_context:your_var_name} 

注意上面標籤中的「your_context」

+0

所以,我現在已將標題中的邏輯更改爲以下格式: { exp:stash:set name =「cf_homepage_main_intro」} {cf_homepage_main_intro} {/ exp:stash:set} 然後使用{exp:stash:cf_homepage_main_intro}並且它仍然不能正常工作 – madebyhippo

+0

我認爲你仍然應該使用set_list和改爲將你的get改爲get_list;正如下面提到的那樣。 – Natetronn

3

問題是我試圖調用同一個模板中的{get},所以需要標籤後面的process ='end'。

此外,僅供參考 - 這是我使用的是什麼:

{exp:stash:set name="cf_homepage_main_intro"}{cf_homepage_main_intro}{/exp:stash:set} 

,然後找回來了(用快捷鍵標記):

{exp:stash:cf_homepage_main_intro process='end'} 

完成任務!