magento模板中XML与phtml关系[三]

 这次继续进行magento模板制作的探讨,上一次说了.xml可以做到.phtml做不到的事情。今天说说xml和phtml是怎么配合着来生成我们的magento模版的。
本次讲解,使用magento 1.4版本,使用base中的default模板。
例子是最快速了解magento的方式了,我们来看下magento头部的搜索框,是怎么显示出来的。
在:app\design\frontend\base\default\layout\catalogsearch.xml 中有声明定义
 
   
1 < default >
2 < reference name = " header " >
3 < block type = " core/template " name = " top.search " as = " topSearch " template = " catalogsearch/form.mini.phtml " />
4 </ reference >
然后在:app\design\frontend\base\default\template\page\html\header.phtml 中调用输出
 
   
1 < div class = " quick-access " >
2 <? php echo $this -> getChildHtml( ' topSearch ' ) ?>
我们看到在XML中有代码片段 as=”topSearch”, 然后在phtml的 getChildHtml( )的参数就是topSearch,所以啊,这就是关键点。
我们要将这个搜索从模板的头部(header)移动到模板的底部(footer)怎么办呢?
那么就先将上面的XML中的<reference name=”header”> 改成<reference name=”footer”>,
然后将app\design\frontend\base\default\template\page\html\header.phtml中 的<?php echo $this->getChildHtml(‘topSearch’) ?>删掉将其添加到:app\design\frontend\base\default\template\page\html \footer.phtml中的适当位置。
这个时候我们就发现
<reference name="header"> 对应的就是app\design\frontend\base\default\template\page\html\header.phtml文件
<reference name="footer"> 对应的就是app\design\frontend\base\default\template\page\html\footer.phtml

为甚么呢?
我们看下:app\design\frontend\base\default\layout\page.xml文件中的定义这个footer和header的代码片段
1 <block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
2  <block type="page/html_wrapper" name="bottom.container" as="bottomContainer" translate="label">
3 <label>Page Footer</label>
4 <action method="setElementClass">
5  <value>bottom-container</value>
6 </action>
7 </block>
8 <block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
9 <block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>
10 </block>
看这第一行代码,就说的很清楚了,name="footer" 并且template="page/html/footer.phtml"。所以这个<reference name="footer">就是在
对footer.phtm中的getChildHtml( )进行定义。
如果是初学者,读到这里还不懂,没关系。因为我开始看着也眼花,我们又不是专业人士,很正常。但是我们要善于去照猫画虎,去总结规律。
我们可能不懂,但是我们会用,这就是一个好的开始,多练。慢慢的就什么都懂了,。

转载于:https://www.cnblogs.com/luoine/archive/2011/06/24/2088574.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值