magento 1.4 -- 自定义变量(Custom Variables)使用初探

简介:

在CMS中使用的变量(Variables)在1.3时代就已经存在,只不过那时候只有少数几个,而且使用时需要自己手写。比如很常用的{{store url=""}}和{{skin url=""}},分别代表网站根url和当前使用模板的文件夹目录。

到了Magento1.4,后台引入了强大的编辑器和自定义变量,变量的使用更加方便而且可以在自带的基础上自己添加新变量了。

首先看下编辑器,打开一个CMS的内容页,编辑器里第一行第一个图标就是插入变量(Insert Variable),或者隐藏编辑器后文本域上四个按钮的最后一个。

点击插入变量,可以看到默认变量的一个列表,点击某个变量就可以在内容相应的位置插入这个变量。

上图的Store Name插入后的结果是{{config path="general/store_information/name"}},前台的显示结果是后台配置->基本设置里的商店名称框里填的内容。

可以看出{{config path="*"}}拿的是后台系统设置里的一些值,而系统设置的值全部都在数据库的core_config_data表,表中就有path字段,尝试把path里的值换成其他配置,比如{{config path="web/unsecure/base_url"}},前台确实能拿到网站根目录。这样可以看出{{config path="*"}}是拿系统配置的一些值的通用写法。

接下来看下自定义变量,打开菜单System->Custom Variables,点击按钮新增一个变量

 

保存之后回到CMS页面去看一下,现在点击插入变量的时候就可以看到刚刚添加的新变量了,点击插入这个新变量,结果是{{customVar code=shuishui_test}}

 

        最终结果

前台显示结果

可以看到后台所填的商店名和自己写的新变量都获取到了。

 

最后,怎么在.phtml文件中使用自定义变量呢,看下面的代码

$variable = Mage::getModel('core/variable')->loadByCode('shuishui_test'); echo $variable->getValue('text'); 

Magento的变量使用的地方很多,这里只是就我了解简单描述了下,有些地方都还有待研究,比如在有些变量只能在邮件模板使用而不能在普通CMS中使用等等。

目录
相关文章
|
2月前
|
JavaScript
报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
|
9月前
|
存储 JSON UED
Flask框架之RESTful--参数验证--add_argument方法参数详解
参数验证的重要性,Flask-RESTful 参数验证方法,add_argument方法参数详解
|
测试技术
loadrunner 运行脚本-Run-time Settings->General->Additional attributes设置
loadrunner 运行脚本-Run-time Settings->General->Additional attributes设置
77 0
|
测试技术 PHP
PHP:laravel自定义Model报错:$table must not be defined/$table must be string
PHP:laravel自定义Model报错:$table must not be defined/$table must be string
102 0
|
Unix Linux iOS开发
FastAPI(64)- Settings and Environment Variables 配置项和环境变量(下)
FastAPI(64)- Settings and Environment Variables 配置项和环境变量(下)
473 0
FastAPI(64)- Settings and Environment Variables 配置项和环境变量(下)
vscode配置eslint自动格式化报错“Auto Fix is enabled by default. Use the single string form“
vscode配置eslint自动格式化报错“Auto Fix is enabled by default. Use the single string form“
260 0
vscode配置eslint自动格式化报错“Auto Fix is enabled by default. Use the single string form“
|
前端开发
前端项目实战2-npm WARN config global --global, --local are deprecated. Use `–location解决方案
前端项目实战2-npm WARN config global --global, --local are deprecated. Use `–location解决方案
597 0
|
前端开发
通过local和global设置类名是否被模块化
通过local和global设置类名是否被模块化
|
Ruby
【Ruby on Rails问题】publish_name.rb文件中定义的变量显示没有定义NameError: uninitialized constant DB_CLASS
在rails项目中,config/initializers/publish_name.rb文件常用来定义的全局变量、全局常量。但是我们虽然在publish_name.rb文件中定义了常量,但是还是显示没有定义。来看一下解决方法。 问题描述: 在publish_name.rb文件中定义了变量DB_CLASS
99 0
|
API 数据库 数据安全/隐私保护
FastAPI(64)- Settings and Environment Variables 配置项和环境变量(上)
FastAPI(64)- Settings and Environment Variables 配置项和环境变量(上)
434 0
FastAPI(64)- Settings and Environment Variables 配置项和环境变量(上)