4

local.xml-- 特にログイン/ログアウトリンクを使用して、トップ リンクを再配置したいと思います。リンクを削除してから再度追加して位置タグを変更しなくても、これは可能ですか?

現在 (そしてデフォルトで) ログインとログアウトは 100 の位置に設定されていcustomer.xmlます:

<customer_logged_in>
    <reference name="top.links">
        <action method="addLink" translate="label title" module="customer">
            <label>Log Out</label>
            <url helper="customer/getLogoutUrl"/>
            <title>Log Out</title>
            <prepare/>
            <urlParams/>
            <position>100</position>
        </action>
    </reference>
</customer_logged_in>

<customer_logged_out>
    <reference name="top.links">
        <action method="addLink" translate="label title" module="customer">
            <label>Log In</label>
            <url helper="customer/getLoginUrl"/>
            <title>Log In</title>
            <prepare/>
            <urlParams/>
            <position>100</position>
        </action>
    </reference>
</customer_logged_out>

両方とも位置 1 に配置したいと思います (経由local.xml)。

アクション メソッドは認識してsetAttributeいますが、この場合の使用方法がわかりません。

4

3 に答える 3

3

内でこれを行うより効率的な方法が見つからなかったlocal.xmlため、リンクを削除し、位置パラメータを変更して再度追加しました。

<customer_logged_in>
    <reference name="top.links">
        <action method="removeLinkByUrl"><url helper="customer/getLogoutUrl"/></action>
        <action method="addLink" translate="label title" module="customer">
            <label>Log Out</label>
            <url helper="customer/getLogoutUrl"/>
            <title>Log Out</title>
            <prepare/>
            <urlParams/>
            <position>4</position>
            <liParams>id="top-logout"</liParams>
            <aParams/>
        </action>
    </reference>
</customer_logged_in>

<customer_logged_out>
    <reference name="top.links">
        <action method="removeLinkByUrl"><url helper="customer/getLoginUrl"/></action>
        <action method="addLink" translate="label title" module="customer">
            <label>Log In</label>
            <url helper="customer/getLoginUrl"/>
            <title>Log In</title>
            <prepare/>
            <urlParams/>
            <position>4</position>
            <liParams>id="top-login"</liParams>
            <aParams/>
        </action>
    </reference>
</customer_logged_out>
于 2012-07-03T14:33:26.450 に答える
1

top.linksブロックのメソッドは、このaddLinkブロックにリンクを追加するために使用されます。そのメソッドの本体を見ると、リンクの位置を決定するために position パラメータが使用されていることがわかります。

リンクの位置は、次のコードのチャンクによって決定されます。

 $this->_links[$this->_getNewPosition($position)] = $link;
 if (intval($position) > 0) {
     ksort($this->_links);
 }

_getNewPosition()メソッドは、その特定のポジションがまだ利用可能かどうかを確認します。そうでない場合は、利用可能な最も近いものを検索します (つまり、位置 1 にはリンクが 1 つしかない可能性があります)。リンクの正しい位置が取得された後、リンクの配列全体がソートされます。

あなたの場合、ログインとログアウトの両方のリンクの位置は、デフォルトで 100 に設定されています (<position />タグを参照)。そのため、レイアウト xml ( customer.xml) をテーマのレイアウト ディレクトリにコピーし、位置パラメーターを 1 に変更する必要があります。

これらのリンクが位置 1 にレンダリングされない場合、他のリンクの位置があなたのリンクより前に 1 に設定されていたことを意味します。そのような場合は、そのリンクの位置をより大きな数に変更してください。ゼロ以下の位置の値は使用できないことに注意してください。

于 2012-07-02T07:02:40.843 に答える
0

以下は、トップリンクの位置番号です。

これらに基づいて、トップリンクの位置を設定または変更できます

My Account = 10 
Whislist = 30 
Mycart = 50 
Checkout = 60
Login/Logout = 100
于 2016-07-20T12:28:10.743 に答える