我坚持以编程方式在 block 中添加 url 链接,我需要将 URL 添加到在 CMS/page 下编辑的自定义页面,我想通过添加如下所示的内容将其添加到 .xml 文件中。
<action method="addLink"
translate="label title"
module="catalog">
<label>My Account</label>
<url helper="customer/getAccountUrl" />
<title>My Account</title>
</action>
上面的示例从模块中检索 url,但不知道静态 CMS/页面 url 应该使用哪些参数。请帮帮我。
最佳答案
让我以 top.links block 为例来解释这一点。
<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>
你的问题的答案很简单。
假设我们需要向顶部链接添加一个新链接,比如说一个名为 Terms and Conditions 的 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>
关于html - Magento,如何在 block 中添加静态 url 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27126323/