【问题标题】:Magento - How can I tell if I'm on a "My Account" page?Magento - 我如何判断我是否在“我的帐户”页面上?
【发布时间】:2015-02-06 15:33:45
【问题描述】:

我想在我的 Magento 网站的页面顶部添加一些内容,但前提是客户位于“我的帐户”部分。我会将其添加到/app/design/frontend/xxxx/xxxx/template/page/html/header.phtml。如何检测客户是否在“我的帐户”部分?

我发现了一些行不通的方法,最接近的是Mage::app()->getFrontController()->getRequest()->getRouteName(),它不能提供一种可靠的方法来检查我是否在“我的帐户”部分。

这些页面在XML中都有<update handle="customer_account" />,有没有办法获取当前页面的句柄?

【问题讨论】:

    标签: magento magento-1.6


    【解决方案1】:

    执行此操作的 magento 方法是编辑您的 local.xml 文件。

    你应该像这样使用customer_account_index句柄:

    <customer_account_index>
      <reference name="header">
        <block type="core/template" name="new_customer_data" template="page/html/customer.phtml"/>
      </reference>
    </customer_account_index>
    

    使用您想要的数据创建page/html/customer.phtml

    然后在template/page/html/header.phtml&lt;?php echo $this-&gt;getChildHtml('new_customer_data') ?&gt;

    另一种方式是:

    <?php $action = Mage::app()->getFrontController()->getAction();
    echo $action->getFullActionName('_');
    if($action->getFullActionName('_')=="customer_account_index")
    {
    
    }?>
    

    【讨论】:

    • 谢谢!这真的很好。我的做法略有不同,我将&lt;reference&gt; 标签放在&lt;customer_account&gt; 标签中,而不是''。这样做的好处是将更新应用于所有客户帐户页面,而不仅仅是“帐户仪表板”。此外,我添加到客户帐户的一些自定义菜单包括&lt;update handle="customer_account" /&gt; 标签,因此它也适用于这些。非常感谢您的精彩回答!
    【解决方案2】:

    试试这个:

    在布局页面中

    <customer_account_index translate="label">
        <label>Custom Page</label>
            <reference name="header">
            <block type="page/header" name="header">
                <action method="setTemplate"><template>your_custom_header_template_path/yourcustomheader.phtml</template></action>
            </block>
        </reference>
        <!-- Mage_Customer -->
        <update handle="customer_account"/>
    </customer_account_index>
    

    参考链接:

    http://www.atwix.com/magento/how-to-change-the-header-of-magento-cms-page/

    http://istockphp.com/magento/adding-custom-page-to-the-customer-account-dashboard/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-08
      • 1970-01-01
      • 1970-01-01
      • 2021-07-12
      • 2012-02-13
      • 1970-01-01
      相关资源
      最近更新 更多