2012-07-14 76 views
3

我正在嘗試在magento中創建一個新頁面,其中我必須添加一些html和javascript。 爲此,我創建了一個模塊。 內容的 - >應用程序\代碼\本地\公司名稱\的HelloWorld \等\ config.xml中 -如何在magento網站中創建新頁面

<?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> 

的內容 - >應用程序\代碼\本地\公司名稱\的HelloWorld \控制器\索引控制器。 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"; 
    } 
} 

>

做這一切後,當我轉到域/ index.php文件/的Helloworld 我可以看到頁眉和頁腳,現在我想在它們之間添加一些「div」標籤和JavaScript。 請說明如何做到這一點。

+1

爲什麼不使用CMS頁面呢? – 2012-07-14 10:52:54

+0

那麼你能告訴我,在哪裏添加html和javascript,因爲當我將代碼粘貼到內容區域時,它會以原樣顯示,而不會呈現它。 – ankit 2012-07-14 10:59:34

+0

有一個按鈕可以在所見即所得的HTML模式之間切換。 – 2012-07-14 12:17:10

回答

7

插入到模塊的​​3210:

<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的任何內容。