本次讲解,使用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 >
2 < reference name = " header " >
3 < block type = " core/template " name = " top.search " as = " topSearch " template = " catalogsearch/form.mini.phtml " />
4 </ reference >
1
<
div
class
=
"
quick-access
"
>
2 <? php echo $this -> getChildHtml( ' topSearch ' ) ?>
2 <? php echo $this -> 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>
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>
对footer.phtm中的getChildHtml( )进行定义。
如果是初学者,读到这里还不懂,没关系。因为我开始看着也眼花,我们又不是专业人士,很正常。但是我们要善于去照猫画虎,去总结规律。
我们可能不懂,但是我们会用,这就是一个好的开始,多练。慢慢的就什么都懂了,。