我知道"自定义变量"以及它们如何与电子邮件模板中的{{}}括号以及静态块一起使用.
但是,我想在模板代码即view.phtml中使用它们.
我希望能够访问'variable plain value'来检索转换值,即一个数字/字符串作为给定'变量代码'的数字.
Fia*_*abs 31
一段时间以来一直在创建可通过管理界面编辑的各种消息,所以当时刻的味道发生变化时,我不必去挖掘代码.
要使用代码访问自定义变量的普通值,请custom_variable_code使用以下命令:
Mage::getModel('core/variable')->loadByCode('custom_variable_code')->getValue('plain');
Run Code Online (Sandbox Code Playgroud)
注意:单个商店不显示变量范围的商店选择下拉列表.这个答案在技术上是不正确的,以便在有多个商店的情况下为自己提供证据 - >请参阅下面的@Mark van der Sanden回答并给他一个upvote.
Mar*_*den 31
不幸的是,所有其他答案都不是100%正确.像这样使用它(注意setStoreId()获取正确的商店视图的值):
$value = Mage::getModel('core/variable')
->setStoreId(Mage::app()->getStore()->getId())
->loadByCode('variable_code')
->getValue('text');
Run Code Online (Sandbox Code Playgroud)
或者获取html值:
$value = Mage::getModel('core/variable')
->setStoreId(Mage::app()->getStore()->getId())
->loadByCode('variable_code')
->getValue('html');
Run Code Online (Sandbox Code Playgroud)
如果未定义html值,getValue()则在请求html值时返回文本值.
ʍǝɥ*_*ʇɐɯ 10
Stackoverflow几乎再次救援.以为这就是它:
但事实并非如此,这是:
$angle = Mage::getModel('core/variable')->loadByCode('angle')->getData('store_plain_value');
Run Code Online (Sandbox Code Playgroud)