如何在magento中添加自己的自定义模板


How to add own custom template in magento

嗨,我尝试在magneto中添加自己的自定义模板,但我无法做到这一点,我使用以下步骤如下所示首先,我在app/code/local

中创建一个自己的目录
   - FirstNameSpace
    - FirstWeb
      -controllers
       -IndexController.php

和IndexController.php的代码为

<?php
class FirstNameSpace_FirstWeb_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $this->loadLayout();
    }
    public function testAction()
    {
        echo "test action";
    }
}

and the magneto app/etc/modules/FirstNameSpace_FirstWeb.xml

代码为

     <?xml version="1.0"?>
<config>
     <modules>
       <FirstNameSpace_FirstWeb>
        <active>true</active>
        <codePool>local</codePool>
        </FirstNameSpace_FirstWeb>
    </modules>
</config>

在app/design/frontend/default/default/layout/firstweb.xml中像这样的代码

<layout version="0.1.0">
    <firstweb_index_index translate="label">
        <label>Contact Us Form</label>
        <reference name="content">
            <block type="core/template" name="contactForm" template="firstweb/form.phtml"/>
        </reference>
    </firstweb_index_index>
</layout>

和模板/firstweb/form中。phtml像

你好!这是第一个例子

和config.xml,像这样

<?xml version="1.0"?>
<config>
    <modules>
        <FirstNameSpace_FirstWeb>
            <version>0.1.0</version>    <!-- Version number of your module -->
        </FirstNameSpace_FirstWeb>
    </modules>
    <frontend>
        <routers>
            <firstweb>
                <use>standard</use>
                <args>
                    <module>FirstNameSpace_FirstWeb</module>
                    <frontName>firstweb</frontName>
                </args>
            </firstweb>
        </routers>
       <!-- This node contains module layout configuration -->
 <layout>
            <updates>
                <contact>
                    <file>firstweb.xml</file>
                </contact>
            </updates>
        </layout>
    </frontend>
</config>

 Now if i hit the page :http://localhost/magento/index.php/firstweb/index   

我没有得到任何回应

请帮助我,这样我就可以加载布局在磁

有很多地方不对。

设置页面模板:

<layout version="0.1.0">
    <firstweb_index_index translate="label">
        <label>Contact Us Form</label>
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
        </reference>
        <reference name="content">
            <block type="core/template" name="contactForm" template="firstweb/form.phtml"/>
        </reference>
    </firstweb_index_index>
</layout>

渲染布局:

<?php
class FirstNameSpace_FirstWeb_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
    public function testAction()
    {
        echo "test action";
    }
}

另外,你的配置是错误的,应该是firstweb而不是contact。Contact正在被核心模块使用Contacts:

         <updates>
            <firstweb>
                <file>firstweb.xml</file>
            </firstweb>
        </updates>

尝试一下,如果仍然不行,继续尝试,直到你完全正确。