magento 构建布局

magento中默认的布局文件为1column.phtml,2columns-left.phtml,2columns-right.phtml,3columns.phtml
其实我们是可以增加自己需要的布局文件的。页面的内容具体要什么样子的,这就看自己的需求了。增加magento布局文件的方法步骤如下。

一、新建一个布局文件newcolumn.phtml 这个newcolumn.phtml根据自己的需要进行设置。大体和默认的几个布局文件的结构一致,调用的内容块一致就ok了.
二、在layout\page.xml中标签里加以下代码,可以参考默认的几个布局文件。

[xml]
<page_new_columns translate="label">
       <label>All new-Column Layout Pages</label>
       <reference name="root">
            <action method="setTemplate"><template>page/newcolumn.phtml</template></action>
            <!-- Mark root page block that template is applied -->
            <action method="setIsHandle"><applied>1</applied></action>
       </reference>
</page_new_columns>
[/xml]

三、在code\core\mage\page\etc\config.xml中这个标签里 下的 里加入以下代码,同样有其他布局文件的写法,(可以参考其他的布局写法)

[xml]
<new_columns module="page" translate="label">
       <label>new column</label>
       <template>page/newcolumn.phtml</template>
       <layout_handle>page_new_columns</layout_handle>
</new_columns>
[/xml]

完成上述的几步之后,在Magento后台选择layout的时候 就会多一项new cloumn的选项。或者是要通过设置catalog.xml在需要调用到该布局文件的地方改成相应的标签就ok了。例如需要在Product view 页面调用该布局文件可以修改

[xml]
<reference name="root">
    <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
</reference>
[/xml]

成相应的

[xml]
<reference name="root">
    <action method="setTemplate"><template>page/newcolumn.phtml</template></action>
</reference>
[/xml]

这样在product view页面就调用了新的布局文件了。这样就给我们前台设计带来的更大的方便。可以根据我们的需要来设定magento的前台显示结果。


你可能感兴趣的:(Magento,magento模块)