如何使用local.xml在Magento 1.5中设置默认布局?

Ree*_*rds 5 xml layout default magento

所以我已经完成了一些我想要使用的布局,并且我认为在local.xml文件中设置它会为每个页面修复此问题.像这样

<default>
<reference name="root">
    <action method="setTemplate">
      <template>page/mytheme.phtml</template>
    </action>
</reference>
</default>
Run Code Online (Sandbox Code Playgroud)

然而,这没有做任何事情.相反,如果我去

...<customer_account_forgotpassword>
  <reference name="root">
    <action method="setTemplate"><template>page/mytheme.phtml</template></action>
  </reference>
</customer_account_forgotpassword>  

<customer_account_confirmation>
  <reference name="root">
    <action method="setTemplate"><template>page/mytheme.phtml</template></action>
  </reference>
</customer_account_confirmation>...
Run Code Online (Sandbox Code Playgroud)

对于每个特定的地方,它都会在这些特定的页面上被更改.我在想错还是这是唯一的方法呢?

Ala*_*orm 11

您(可能)遇到的问题是稍后会出现问题并再次为根块设置模板,从而覆盖您的更改.

更新版本的Magento(1.4somethingish)介绍了一种防止这种情况发生的方法.如果你看page.xml,你会看到这样的手柄

<page_one_column translate="label">
    <label>All One-Column Layout Pages</label>
    <reference name="root">
        <action method="setTemplate"><template>page/1column.phtml</template></action>
        <!-- Mark root page block that template is applied -->
        <action method="setIsHandle"><applied>1</applied></action>
    </reference>
</page_one_column>
Run Code Online (Sandbox Code Playgroud)

如果page_one_column句柄应用于您的请求,或者您手动应用它

<update handle="page_one_column" />
Run Code Online (Sandbox Code Playgroud)

Magento将更改模板setIsHandle在块上调用方法.

<action method="setIsHandle"><applied>1</applied></action>
Run Code Online (Sandbox Code Playgroud)

Magento中的代码将查找IsHandle属性,如果是真的,setTemplate将忽略进一步的调用.(这有点过分简化了事情,但或多或​​少都是真的)

尝试类似的东西

<default>
    <reference name="root">
        <action method="setTemplate">
          <template>page/mytheme.phtml</template>
        </action>
        <action method="setIsHandle">
            <applied>1</applied>
        </action>       
    </reference>
</default>  
Run Code Online (Sandbox Code Playgroud)

看看是否有帮助.

请记住,这是一个灰色地带,不清楚第三方开发商是否应该采取行动.此外,更改所有页面的模板可能会对期望位于特定模板中的部分网站产生不希望的影响.

  • 很遗憾,但setIsHandle方法用于不同的目的.它背后的想法只是为了保持页面布局向后兼容,因为以前的版本有可能只设置模板,但后来,它被改为处理,更灵活.如果is_handle属性设置为true,它只是不会在页面/布局帮助器中设置模板,但它将应用设置模板的页面句柄,因此模板将被设置,无论如何设置,将如何设置,将是不同. (2认同)