3

私はいくつかのhtmlとjavascriptを追加する必要があるmagentoで新しいページを作成しようとしています。このために、モジュールを作成しました。-> 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 に答える