3

我正在尝试在 magento 中创建一个新页面,我必须在其中添加一些 html 和 javascript。为此,我创建了一个模块。-> 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>

-> 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";
  }
 }

?>

完成所有这些后,当我转到 domain/index.php/Helloworld 时,我可以看到页眉和页脚,现在我想在它们之间添加一些“div”标签和 javascript。请解释如何做到这一点。

4

1 回答 1

9

插入到模块的config.xml

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

接下来添加布局文件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>

最终添加任何内容的 phtml 文件app/design/frontend/default/default/template/helloworld/index.phtml

于 2012-07-16T08:29:43.540 回答