How to create new page in magento site

倾然丶 夕夏残阳落幕 提交于 2019-12-02 00:05:41

问题


I am trying to create a new page in magento ,in which I have to add some html and javascript. For this ,I have created a module . Contents of -> app\code\local\CompanyName\HelloWorld\etc\config.xml -

 <?xml version="1.0"?>
 <config>
<modules>
    <CompanyName_Helloworld>
        <version>
            0.1.0
        </version>
    </CompanyName_Helloworld>
</modules>
<frontend>
    <routers>
        <helloworld>
            <use>standard</use>
            <args>
                <module>CompanyName_Helloworld</module>
                <frontName>Helloworld</frontName>
            </args>
        </helloworld>
    </routers>

</frontend>

Contents of -> app\code\local\CompanyName\HelloWorld\controllers\IndexController.php -

<?php
 class CompanyName_Helloworld_IndexController extends   Mage_Core_Controller_Front_Action{
public function indexAction(){
    $this->loadLayout();
           $this->renderLayout();
    //echo "We're echoing just to show that this is what's called, normally you'd have some kind of redirect going on here";
  }
 }

?>

After doing all this when I goto domain/index.php/Helloworld I can see the header and the footer,Now I want to add some "div" tags and javascript between them. Please Explain how to do it.


回答1:


Insert to module's config.xml:

<frontend>
...
  <layout>
    <updates>
      <helloworld>
        <file>helloworld.xml</file>
      </helloworld>
    </updates>
  </layout>
</frontend>

Next add layout file app/design/frontend/default/default/layout/helloworld.xml:

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
  <helloworld_index_index>
    <reference name="content">
      <block type="helloworld/index" name="helloworld_any_block" template="helloworld/index.phtml" />
    </reference>
  </helloworld_index_index>
</layout>

Eventually add phtml file app/design/frontend/default/default/template/helloworld/index.phtml with any content.



来源:https://stackoverflow.com/questions/11483097/how-to-create-new-page-in-magento-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!