我知道‘自定义变量’,以及如何在电子邮件模板和静态块中使用{{ }}括号。
但是,我想在模板代码中使用它们,即view.phtml。
我希望能够访问'variable plain value‘来检索转换值,即一个数字/字符串作为给定'variable code’的数字。
发布于 2013-08-02 04:00:19
不幸的是,所有其他答案都不是100%正确的。像这样使用它(注意setStoreId()
以获取正确商店视图的值):
$value = Mage::getModel('core/variable')
->setStoreId(Mage::app()->getStore()->getId())
->loadByCode('variable_code')
->getValue('text');
或者获取html值:
$value = Mage::getModel('core/variable')
->setStoreId(Mage::app()->getStore()->getId())
->loadByCode('variable_code')
->getValue('html');
如果未定义html值,则当您请求html值时,getValue()
将返回文本值。
发布于 2011-06-03 06:46:41
Stackoverflow几乎又一次拯救了我们。我想这就是了:
Setting a global variable in Magento, the GUI way?
但事实并非如此,这是:
$angle = Mage::getModel('core/variable')->loadByCode('angle')->getData('store_plain_value');
发布于 2011-06-03 06:35:34
我看到的唯一方法是通过在模板块中有一个方法来实现这一点,它将输出所需的结果。
例如,假设在模板view.phtml中,您有以下代码:
<div id="title_container">
<h2><?= $this->getTitle(); ?></h2>
</div>
该函数可以表示您的变量代码,任何与标题中显示的内容相关的逻辑都应该放在块中。
为了澄清起见,该块是变量$this
如果您不确定块的实际类名是什么,可以执行以下操作:
Mage::log(get_class($this));
在var/log/system.log中,您将打印该模板的块的类。
这是最好的方法。
HTH :)
https://stackoverflow.com/questions/6221054
复制相似问题