2012-11-27 28 views
1

是否可以在佈局文件中使用Custom Variables?我可以在這樣的模板文件中使用它們:Magento:在佈局文件中使用自定義變量

Mage::getModel('core/variable')->loadByCode('variableCode')->getData('store_plain_value') 

但是不確定與xml文件。

我知道我可以使用上面的代替,但是這對於將來的使用也知道。

更新:恐怕我最不清楚了。我專門尋找訪問管理面板「自定義變量」部分,不只是將我自己的變量傳遞給塊。我對缺乏清晰度表示歉意。

回答

2

基於更新的問題:

創建一個輔助類包裝了core/variable功能,如:

class Some_Module_Helper_Variable 
{ 
    public function getVariableData($code,$param) 
    { 
     return Mage::getModel('core/variable')->loadByCode($code)->getData($param); 
    } 
} 

然後,在佈局XML爲你塊,你可以做到這一點(我相信):

<action method="setSomeVal"> 
    <arg helper="class_group/variable/getVariableData"> 
     <arg1>variableCode</arg1> 
     <arg2>store_plain_value</arg2> 
    </arg> 
</action> 
+1

只需提一下:當你使用多個商店視圖時,它的好處就是添加這個: 'Mage :: getModel('core/variable') - > setstoreid(Mage :: app() - > getstore() - > getid )) - > loadByCode($代碼) - >的getData($ PARAM)' – arekstasiewicz

4

你有沒有嘗試以下方法:

<!-- in layout xml file --> 
<action method="setData"><name>color_id</name><value>5</value></action> 

然後,您可以在塊文件中使用如下:

$colors = $this->getColorId(); 
# or 
    $colors = $this->getData('color_id'); 
+0

我在我的問題似乎最不清楚,我很抱歉。請參閱更新。 +1雖然答案。 –

4

Mage_Core_Block_Abstract延伸Varien_Object並繼承了它__call()超載。而在佈局XML調用塊的方法塊的動作,下面是可能的:

傳遞一個字符串(它可以翻譯!):

<action method="setSomeVal" translate="arg" module="some/helper"> 
    <arg>Some String</arg> 
</action> 

傳遞一個數組:

<action method="setSomeVal"> 
    <arg> 
     <key1>Some String</key1> 
     <key2>Some String</key2> 
     <key3> 
      <multikey1>Some String</multikey1> 
     </key3> 
    </arg> 
</action> 

通行證任何你想要的:

<action method="setSomeVal"> 
    <arg helper="some/helper/method"> 
     <param_for_the_helper_method> 
      <getting_crazy>Oh Boy.</getting_crazy> 
     </param_for_the_helper_method> 
</action> 

檢索塊/模板中的值與$this->getSomeVal();

好玩嗎?

+0

我似乎很不清楚我的問題,我很抱歉。請參閱更新。 +1雖然答案。 –