2014-11-25 71 views
0

我堅持以編程方式在塊中添加url鏈接,我需要添加一個URL到編輯在CMS /頁面下的自定義頁面,並且我想將其添加到.xml文件中通過添加下面的東西。Magento,如何在塊中添加靜態url鏈接

<action method="addLink" 
     translate="label title" 
     module="catalog"> 
     <label>My Account</label> 
     <url helper="customer/getAccountUrl" /> 
     <title>My Account</title> 
</action> 

上面的示例從模塊中檢索url,但不知道靜態CMS /頁面url應該使用哪些參數。請幫助我。

回答

2

讓我以top.links塊爲例來說明這一點。

<block type="page/template_links" name="top.links" as="topLinks"/> 

「addLink」函數在Mage_Page_Block_Template_Links中定義。該功能的定義是

public function addLink($label, $url='', $title='', $prepare=false, $urlParams=array(), 
     $position=null, $liParams=null, $aParams=null, $beforeText='', $afterText='') 

此外,其中的html代碼寫入的phtml文件是'page/template/links.phtml'。

<reference name="top.links"> 
    <block type="wishlist/links" name="wishlist_link"> 
     <action method="addWishlistLink"></action> 
    </block> 
</reference> 

回答你的問題很簡單。

假設我們需要添加一個新的鏈接到頂部鏈接,可以說一個名爲條款和條件的CMS頁面的鏈接。要做到這一點打開一個佈局文件,讓說customer.xml並添加以下代碼:

<default> 
<reference name="top.links"> 
    <action method="addLink" translate="label title"> 
    <label>Terms and Condition</label> 
    <url>terms</url> 
    <title>Terms and Condition</title> 
    <prepare>true</prepare> 
    <position>2</position> 
    </action> 
</reference> 
</default> 
+0

如果URL的值是計算,那麼這一個的完整路徑www.XXX.com/index.php /條款?此外,翻譯領域在行動中的用法定義如何? – 2014-11-26 02:41:34

+0

當您看到translate =「label」module =「customer」時,這會告訴Magento它應該在