使用local.xml和addlink方法来自定义toplinks

以前总是用暴力的方法来自定义top links,方法是直接改links.phtml的html。Links由Mage_Page_Block_Template_Links这个类生成,其实用的是Varien_Object。最近决定更正这个暴力的行为。

首先,local.xml我们应该知道,可以覆盖布局的行为。这个在app/code/core/Mage/Core/Model/Layout/Update.php 的418行可以看到,我用的是magento 1.5.1.0版本。

<?xml version="1.0"?>
<layout version="0.1.0">
	<default>
		<reference name="root">
			<reference name="top.links">
				<action method="addLink" translate="label title">
					<label>About Us</label>
					<url>about</url>
					<title>About Us</title>
					<prepare>true</prepare>
					<position>999</position>
					<liParams/>
					<aParams>class="top-link-about-us"</aParams>
					<beforeText>id="alink"</beforeText>
					<afterText>Text</afterText>
				</action>
			</reference>
		</reference>
	</default>
</layout>

如上的local.xml出来的效果是这样的:


有些奇怪...beforeText和afterText都不太对劲..似乎跟字面意思不符合...需要继续深入地研究内核才行...

如果用这样的xml的话

				<action method="removeLinkByUrl"><url helper="customer/getAccountUrl"/></action>
				
				<action method="addLink" translate="label title" module="customer">
					<label>My Custom Account</label>
					<url helper="customer/getAccountUrl"/>
					<title>My Account</title>
					<prepare/>
					<urlParams/>
					<position>10</position>
				</action>
出来的结果变成这样:


移除的话你可以使用remove name或者removeLinkByUrl

				<action method="removeLinkByUrl"><url helper="customer/getAccountUrl"/></action>
				
				<remove name="checkout_cart_link"/>

这样对于开发以来toplinks的模块来说,是再灵活不过了..好了,打算开始做基于ajax的login logout,这个应该派得上用场...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值