Magento:如何在 PHP 中访问自定义变量? [英] Magento: how do I access custom variables in PHP?

查看:23
本文介绍了Magento:如何在 PHP 中访问自定义变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道自定义变量"以及如何在电子邮件模板和静态块中将它们与 {{ }} 括号一起使用.

I am aware of 'Custom Variables' and how they can be used with {{ }} brackets in email templates as well as in static blocks.

但是,我想在模板代码中使用它们,即 view.phtml.

However, I want to use them in template code i.e. view.phtml.

我希望能够访问变量纯值"以检索转换值,即数字/字符串作为给定变量代码"的数字.

I want to be able to access 'variable plain value' to retrieve a conversion value, i.e. a number/string as number for a given 'variable code'.

推荐答案

这样做已经有一段时间了,以创建可通过管理界面编辑的各种消息,因此我不必在当下流行时去挖掘代码变化.

Been doing this for some time to create various messages that are editable through the admin interface so I don't have to go code digging when the flavor of the moment changes.

要使用代码custom_variable_code访问自定义变量的普通值,请使用:

To access the plain value of the custom variable with code custom_variable_code use this:

Mage::getModel('core/variable')->loadByCode('custom_variable_code')->getValue('plain');

注意:单个商店不显示变量范围的商店选择下拉列表.这个答案在技术上是不正确的,为了在拥有多家商店的情况下证明自己的未来 -> 请参阅下面的@Mark van der Sanden 回答并给他一个赞.

NOTE: Single store doesn't show the store select dropdown for the variable scope. This answer is not technically correct, in order to future-proof yourself in case of having multiple stores --> Please see @Mark van der Sanden answer below and give him an upvote.

这篇关于Magento:如何在 PHP 中访问自定义变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆