
这次继续进行magento模板制作的探讨,上一次说了.xml可以做到.phtml做不到的事情。今天说说xml和phtml是怎么配合着来生成我们的magento模版的。
本次讲解,使用magento 1.4版本,使用base中的default模板。
例子是最快速了解magento的方式了,我们来看下magento头部的搜索框,是怎么显示出来的。
在:app\design\frontend\base\default\layout\catalogsearch.xml 中有声明定义
<default> <reference name="header"> <block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/> </reference>
然后在:app\design\frontend\base\default\template\page\html\header.phtml 中调用输出
<div class="quick-access"> <?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的代码片段<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml"> <block type="page/html_wrapper" name="bottom.container" as="bottomContainer" translate="label"> <label>Page Footer</label> <action method="setElementClass"><value>bottom-container</value></action> </block> <block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/> <block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/> </block>看这第一行代码,就说的很清楚了,name="footer" 并且template="page/html/footer.phtml"。所以这个<reference name="footer">就是在
对footer.phtm中的getChildHtml( )进行定义。
如果是初学者,读到这里还不懂,没关系。因为我开始看着也眼花,我们又不是专业人士,很正常。但是我们要善于去照猫画虎,去总结规律。
我们可能不懂,但是我们会用,这就是一个好的开始,多练。慢慢的就什么都懂了,。
转载表明出处:hellokeykey.com
那么,我想问个问题 checkout/cart 这个我想单独从sidebar里调出来,放到header里。那type是什么呢?
首先你要在page.xml的header里面先声明下,就是将原来的cart sidebar的xml贴过来,新加个as=“mini_cart”的属性好在phtml中输出。然后在你的,header.phtml中使用getChildHtml(‘mini_cart’) ?> 来显示出来。
我刚好写个这个东西,在头部弹出购物车。
多谢了。刚用magento用起来还不是特别习惯。。。正在尝试做一套自己的模版。以后还会有问题向你请教~~
恩,你可以使用magento的blank模板,是个很好的基础模板。
支持支持。。。
问一下 我要是在catalog.xml 的左栏增加一个自己定义的block 如何做呢 这个block对应的.phtml是在template/catalog/leftnavall.phtml
对应的.phtml文件在哪里都行。你google“magento add block to left”,有不少教程。顺便看下我的“xml与phtml”关系的文章吧
钥匙请问一下phtml中有许多像getWelcome()的get方法我要到哪里去找。(这好像是php的方法吧)。
php混编,去他们对应的核心文件找
钥匙哥,我现在magento模版已经建好了但是我想改或者在前台头部上加一个头部图片,这在后台上能实现吗?要不要去后台代码区改代码。
钥匙请问一下:后台代码getLogoAlt() ?><a href="getUrl(”) ?>” title=”getLogoAlt() ?>” class=”logo”><img src="getLogoSrc() ?>” alt=”getLogoAlt() ?>” />
前台代码:Magento Commerce
我要怎么找到后台代码中的get方法(如:getLogoSrc() ),怎么让他成为前台代码那要。