【问题标题】:Add link in Magento for custom module在 Magento 中为自定义模块添加链接
【发布时间】:2012-11-07 07:37:55
【问题描述】:

我正在 magento 中为供应商创建一个模块。我想要供应商登录链接top.links.

如何添加链接?

另外,谁能告诉我magento/app/design/frontend/base/default/layout/customer.xml<customer_logged_out><customer_logged_in>等标签的含义

因为我在中使用了<supplier_logged_in><supplier_logged_out>

magento/app/design/frontend/default/default/layout/supplier.xml 不工作。

这是我文件中的示例代码

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

还有任何关于&lt;customer_logged_in&gt; 文件的参考可以使其正常工作吗?

【问题讨论】:

    标签: php xml magento magento-1.5


    【解决方案1】:

    这里是如何在顶部链接中添加自定义链接,更多信息可以在这里找到http://www.classyllama.com/development/magento-development/editing-magentos-top-links-the-better-way

    <reference name="top.links">
                        <!-- Add custom links. Pretty self-explanatory.
                        Dig into app/code/core/Mage/Page/Block/Template/Links.php for more info -->
                        <action method="addLink" translate="label title">
                            <label>About Us</label>
                            <url>about</url>  <!-- can use full url also -->
                            <title>About Us</title>
                            <prepare>true</prepare> <!-- set true if adding base url param -->
                            <urlParams helper="core/url/getHomeUrl"/> <!-- base url - thanks @Russ! -->
                            <!-- there are a few param you can send to do different things in <urlParams> 
                                     dig into app/code/core/Mage/Core/Model/Url.php, around line 803 -->                   
    
                            <!-- below adds #add-fragment to the end of your url -->
                            <!-- <urlParams><_fragment>add-fragment</_fragment></urlParams> -->
    
                            <!-- below adds ?add-query to the end of your url -->
                            <!-- <urlParams><_query>add-fragment</_query></urlParams> -->
    
                            <!-- below gives you a new session id (i think...)-->
                            <!-- <urlParams><_nosid>true</_nosid></urlParams> -->
    
                            <!-- below replaces double quotes, single quotes, greater than, and less than signs 
                                     to their respective url escaped replacements (%22, %27, %3E, %3C) -->
                            <!-- <urlParams><_escape>i'm-a-blog-url</_escape></urlParams> -->
    
                            <position>1</position>
                            <liParams/>
                            <aParams>class="top-link-about-us"</aParams>
                            <beforeText></beforeText>
                            <afterText></afterText>
                        </action>
        </reference>
    

    您需要在&lt;default&gt; 节点或&lt;customer_logged_out&gt;&lt;customer_logged_in&gt; 中添加上述代码(Magento 使用这两个句柄在客户登录或注销您的商店时添加功能)。

    //app/core/Mage/Core/Model/Layout/Update.php.
    class Mage_Customer_Model_Observer
    {
        public function beforeLoadLayout($observer)
        {
            $loggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
    
            $observer->getEvent()->getLayout()->getUpdate()
               ->addHandle('customer_logged_'.($loggedIn?'in':'out'));
        }
    }
    

    要在扩展中使用&lt;supplier_logged_in&gt;(如果需要),首先需要在 Magento 自定义扩展中添加自定义布局句柄。要开始挖掘它,我推荐以下文章:

    http://magebase.com/magento-tutorials/creating-custom-layout-handles/

    http://www.classyllama.com/magento/add-custom-layout-handles-e-g-parent-categories

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多