- 浏览: 71994 次
- 性别:
- 来自: 上海
最新评论
Magento的cms页面和static block页面中可以用一些指示符来得到相应的信息,如{{skin url=".."}} {{media url="..."}}等。
在Mage_Cms_Block_Page类的_toHtml方法中可以找到下面的代码:
先获得负责页面解析的processor对象,然后由processor对象负责对页面中的指示符进行解析和替换工作。
查找cms helper类的getPageTemplateProcessor方法,我们得知processor对象是Mage_Cms_Model_Template_Filter类的实例。Mage_Cms_Model_Template_Filter继承自Mage_Core_Model_Email_Template_Filter类,在Mage_Core_Model_Email_Template_Filter类中定义了负责解析相应指示符的一些方法:
等,可以看到其实cms filter里面已经定义了var指示符,但是我们在cms页面的content里面插入{{var customer.name}}并不能正确被解析,原因是customer变量的值没有设置。
我们只要新建一个模块,继承Mage_Core_Model_Email_Template_Filter类,并设置customer变量的值为当前用户即可。
同时需要新建自定义的helper类,并重写getPageTemplateProcessor方法,返回我们自己的Filter类:
最后,我们重写Mage_Cms_Block_Page类的_toHtml方法:
在config.xml中加入:
我们就可以直接在cms内容里加入customer的一些信息了。
如:
{{var customer.email}}
{{var customer.firstname}}
Magento在解析cms页面时,会把上面的指示符替换为当前用户的相应属性。
在Mage_Cms_Block_Page类的_toHtml方法中可以找到下面的代码:
$helper = Mage::helper('cms'); $processor = $helper->getPageTemplateProcessor(); $html = $processor->filter($this->getPage()->getContent()); ...
先获得负责页面解析的processor对象,然后由processor对象负责对页面中的指示符进行解析和替换工作。
查找cms helper类的getPageTemplateProcessor方法,我们得知processor对象是Mage_Cms_Model_Template_Filter类的实例。Mage_Cms_Model_Template_Filter继承自Mage_Core_Model_Email_Template_Filter类,在Mage_Core_Model_Email_Template_Filter类中定义了负责解析相应指示符的一些方法:
public function blockDirective($construction) public function layoutDirective($construction) public function varDirective($construction)
等,可以看到其实cms filter里面已经定义了var指示符,但是我们在cms页面的content里面插入{{var customer.name}}并不能正确被解析,原因是customer变量的值没有设置。
我们只要新建一个模块,继承Mage_Core_Model_Email_Template_Filter类,并设置customer变量的值为当前用户即可。
public function __construct(){ $variables = array('customer'=>Mage::getSingleton('customer/session')->getCustomer()); $this->setVariables($variables); }
同时需要新建自定义的helper类,并重写getPageTemplateProcessor方法,返回我们自己的Filter类:
public function getPageTemplateProcessor() { return Mage::getModel('glscms/template_filter'); }
最后,我们重写Mage_Cms_Block_Page类的_toHtml方法:
在config.xml中加入:
<cms> <rewrite> <page>Glamour_GlsCms_Block_Cms_Page</page> </rewrite> </cms>
class Glamour_GlsCms_Block_Cms_Page extends Mage_Cms_Block_Page { protected function _toHtml() { $helper = Mage::helper('glscms'); $html = parent::_toHtml(); if($helper->isEnabled()){ $processor = $helper->getPageTemplateProcessor(); $html = $processor->filter(parent::_toHtml()); } return $html; } }
我们就可以直接在cms内容里加入customer的一些信息了。
如:
{{var customer.email}}
{{var customer.firstname}}
Magento在解析cms页面时,会把上面的指示符替换为当前用户的相应属性。
发表评论
-
Magento随机生成sales rule的coupon code
2013-01-02 22:09 2229在Magento中可以使用SalesRule模块下的Mage_ ... -
Magento 后台配置中实现日期选择 (Date picker)
2012-12-28 15:07 2461首先,创建一个新的Form Field 类: <?p ... -
获得指定customer 购买的产品数据
2011-12-10 20:54 1311获得指定customer 购买的产品信息,如果是configu ... -
将缺货产品放在产品列表后面
2011-12-10 20:50 1364Rewrite Mage_Catalog_Model_Laye ... -
Mac Lion上安装配置Nginx PHP PHP-FPM
2011-12-10 16:01 7994<!--?xml version="1.0&q ... -
How to customize Magento as CMS system (1.5.0 CE)
2011-03-06 22:42 1023Before install: 1. Go to app/et ... -
How to redirect to another url in block or template
2011-02-25 13:47 1093In Block class: public funct ... -
Use call back function to proccess Magento large collection
2011-01-19 12:58 912$orders = Mage::getModel('sal ... -
How to remove unnecessary columns in Magento collection
2011-01-19 12:56 1086$orders = Mage::getModel('sal ... -
How to calculate currency according to reward points rate in Magento
2011-01-13 18:03 1288$rate = Mage::getModel('enter ... -
Magento二次开发的利器:Rewrite
2010-12-08 17:15 2704Magento是一个十分优秀的电子商务系统,但是有时候我们需要 ... -
增加Magento后台管理功能三:在后台设置(System/Configuration)中加入自定义设置
2010-11-30 16:17 1946在模块的etc目录下新建system.xml配置文件,内容如下 ... -
增加Magento后台管理功能二:开发后台Controller
2010-11-30 16:02 2683在模块的controllers目录下创建Adminhtml目录 ... -
增加Magento后台管理功能一:在后台管理界面加入菜单
2010-11-30 15:47 4494在模块的etc目录下增加adminhtml.xml配置文件,用 ... -
Magento根据不同的浏览器自动切换package或 theme
2010-11-26 10:05 2027在后台设置中: System > Configurat ... -
Magento让后台数据列表中的action列链接在新窗口打开
2010-11-08 16:56 1126'actions' => array( ... -
Maegen获得后台当前用户的信息
2010-11-08 16:53 840$admin = Mage::getSingleton(' ... -
Magento中用子类替换Block
2010-10-15 10:47 1823Step 1:创建一个新的Module Step 2: 编辑模 ... -
Magento中添加带有选项的属性
2010-10-14 14:49 1417下面的代码为Customer实体添加了性别属性,有两个可选值 ... -
Magento为后台用户保存操作日志(企业版)
2010-09-19 17:00 2728protected function _logAdm ...
相关推荐
Ability to place any block in any position by easily changing CMS page layout Unlimited number of blocks inside each position Unlimited number of content items inside each block Block items can ...
这是一个关于matento在代码中调用cms块得说明
magento中文用户指南
2 新颖的功能像是产品标签、多送货地址或产品比较系统等功能,您不需要支付额外的费用来取得,在现成的 Magento 系统中,您可以发现更多。3 专业与社群支援不像是其他的开放原始码解决方案, Magento 提供专业、可...
像是产品标签、多送货地址或产品比较系统等功能,您不需要支付额外的费用来取得,在现成的 Magento 系统中,您可以发现更多。 3 专业与社群支援 不像是其他的开放原始码解决方案, Magento 提供专业、可信赖的支援...
特征在CMS编辑表单上,将图片上传器添加到Magento后端在后端上传的图像可以在前端int的相应页面中查看易于在任何magento安装中使用安装✓通过作曲家安装在Magento 2根文件夹中运行以下命令: composer require ...
magento用户中文操作手册,学习magento后台管理
magento用户中文操作手册,学习magento后台管理
magento 官方中文语言包
magento中文手册 magento教程
magento中文用户指南,描述magento开发和配置过程
有magento大师编写的免费magento中文开发教程。
magento用户使用手册
magento1.6.1简体中文语言包最新
本文档提供了创建和 Magento的应用程序进行安装定制的店面主题的说明。它描述 Magento的内容呈现过 程,并说明该系统的对有效地建立一个主题要求的范围内的观点层。该文件还走过日常前端开发人员的任 务。
最新magento 商城中文语言包,翻译全面,支持最新magento 1.6
magento最新版中文语言包 Magento (麦进斗) 是一套专业开源的电子商务系统。Magento设计得非常灵活,具有模块化架构体系和丰富的功能。易于与第三方应用系统无缝集成。其面向企业级应用,可处理各方面的需求,...
magento中文操作手册,详细介绍magento的具体操作
NULL 博文链接:https://justcoding.iteye.com/blog/1725217