0

在 Magento 中,最好不创建一个全新的模块,如何将现有模块的布局加载到我自己的模板中?

例如:我想加载“用户帐户仪表板”布局,但我想加载它以便我可以控制它与默认设置分开的外观。

结构如下:

  1. 我创建了一个带有 url “门户”的 CMS 页面。所以,导航是“ http://website.com/portal

  2. CMS 页面使用“include()”来加载“/root/portal/portal.php”。这是我定义一个扩展 Mage_Page_Block_Html 的类的地方。

  3. 然后我添加了一个函数“renderDashboard()”从现有的仪表板布局加载到仪表板中。

  4. 我已将“/app/base/default/customer/account/dashboard.phtml”复制到“/root/portal/content/dashboard.phtml”以用作模板。在我的“dashboard.phtml”中,我希望“$this”对象的功能与之前的“dashboard.phtml”中的功能完全相同

“/root/portal/portal.php”

class Portal_Block extends Mage_Page_Block_Html 
{
    public function renderDashboard()
    {
        $layout = Mage::getSingleton('core/layout');

        //Load existing "customer/account_dashboard" block into my own "dashboard.phtml"
        $block = $layout->createBlock('customer/account_dashboard')->setTemplate('/root/portal/content/dashboard.phtml');

        //Need to now add it
        //$block->renderLayout(); 
    }
}

如果这不可能,我将不得不在我的门户中重写整个帐户仪表板模块......所以,我真的希望它是可能的!

4

1 回答 1

0

第 1 步:创建重定向

创建重写规则,portal/指向customer/account/

  1. 转到Catalog > URL Rewrite Management,单击Add URL Rewrite 按钮
  2. 将类型更改为custom
  3. ID 路径设置为portal
  4. 请求路径设置为portal
  5. 目标路径设置为customer/account/
  6. 重定向设置为No
  7. 保存按钮

通过转到 直接测试yoursite.com/portal。它应该自动加载customer/account/页面。

现在将旧customer/account/链接重定向回/portal

  1. 转到Catalog > URL Rewrite Management,单击Add URL Rewrite 按钮
  2. 将类型更改为custom
  3. ID 路径设置为redirect_to_portal
  4. 请求路径设置为customer/account/
  5. 目标路径设置为portal
  6. 重定向设置为Permanent (301)
  7. 保存按钮

前往 进行测试yoursite.com/customer/account/。它应该自动重定向到/portal

步骤 2:修改帐户页面模板

帐户页面由几个模板文件组成。这些文件位置可能略有不同,具体取决于您是否使用自定义模板以及该模板是否覆盖 Magento 基本模板文件。

看下app/design/frontend/default/base/template/customer/account/

在这里,您将找到.phtml与帐户页面相关的文件。如果您有一个覆盖这些文件的自定义模板,您将需要修改模板目录中的文件。例子:app/design/frontend/[TEMPLATE_NAME]/[TEMPLATE_NAME]/template/customer/account/

dashboard.phtml文件是仪表板页面的主要模板文件。

您还可以查看app/design/frontend/default/base/layout/customer.xml并查找<customer_account_index>标签。在这里,您可以看到哪些.phtml文件和哪些块正在加载到帐户模板中。

于 2013-06-20T15:37:14.190 回答