php Magento 我的帐户布局 XML 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1087733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Magento My Account Layout XML Problem
提问by Remy
I'm having issues getting the customer.xml layout file to work properly for the customer's "my account" pages.
我在让 customer.xml 布局文件为客户的“我的帐户”页面正常工作时遇到问题。
The navigation links and the previously ordered items that are usually on the left hand side of the page won't show up on the page, but if I change the reference name to "content" in the xml file, it shows up (except it's obviously then on the right hand side). I've checked the template it's referencing (2columns-left.phtml), and the getChildHtml('left') is there in the correct position.
通常位于页面左侧的导航链接和先前订购的项目不会显示在页面上,但是如果我将 xml 文件中的引用名称更改为“内容”,它会显示(除了它是显然然后在右手边)。我检查了它引用的模板 (2columns-left.phtml),并且 getChildHtml('left') 在正确的位置。
The block that's causing the problem:
导致问题的块:
<customer_account>
<!-- Mage_Customer -->
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
</reference>
<reference name="left">
<action method="unsetChild"><name>catalog.navigation.all</name></action>
<action method="unsetChild"><name>callout.sendcard</name></action>
<action method="unsetChild"><name>callout.specialorder</name></action>
<block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
<action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
<action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
<action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
</block>
<block type="sales/reorder_sidebar" name="sale.reorder.sidebar" as="reorder" template="sales/reorder/sidebar.phtml"/>
<remove name="tags_popular"/>
</reference>
</customer_account>
This was basically copied straight over from another one of our sites where this works 100%. I've tried everything I can think of (changing the name of the reference in both the template and the layout xml, for example) to no avail. The templates that the layout is referencing are obviously working because they do show up when put into the "content" area.
这基本上是从我们的另一个网站直接复制过来的,该网站 100% 有效。我已经尝试了我能想到的所有方法(例如,更改模板和布局 xml 中的引用名称)都无济于事。布局引用的模板显然是有效的,因为它们在放入“内容”区域时确实会显示出来。
This installation of magento is version 1.3.1.1.
本次安装的 magento 版本为 1.3.1.1。
I appreciate any advice you have to give me...
我很感激你给我的任何建议......
Update: I tried changing the reference to "global_messages", and it doesn't show there either. It only seems to work in the "content" section.
更新:我尝试更改对“global_messages”的引用,但它也没有显示在那里。它似乎只适用于“内容”部分。
Update 2: These are the results of using the "showLayout=page" query string on the page when used with Alan Storm's very handy debugging module (which you'll find in his answer below).
更新 2:这些是在与 Alan Storm 非常方便的调试模块(您将在下面的回答中找到)一起使用时在页面上使用“showLayout=page”查询字符串的结果。
<?xml version="1.0"?>
<layout><block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
<block type="page/html_head" name="head" as="head">
<action method="addJs">
<script>prototype/prototype.js</script>
</action>
<action method="addJs">
<script>prototype/validation.js</script>
</action>
<action method="addJs">
<script>paypoint/validation.js</script>
</action>
<action method="addJs">
<script>scriptaculous/builder.js</script>
</action>
<action method="addJs">
<script>scriptaculous/effects.js</script>
</action>
<action method="addJs">
<script>scriptaculous/dragdrop.js</script>
</action>
<action method="addJs">
<script>scriptaculous/controls.js</script>
</action>
<action method="addJs">
<script>scriptaculous/slider.js</script>
</action>
<action method="addJs">
<script>varien/js.js</script>
</action>
<action method="addJs">
<script>varien/form.js</script>
</action>
<action method="addJs">
<script>varien/menu.js</script>
</action>
<action method="addJs">
<script>mage/translate.js</script>
</action>
<action method="addJs">
<script>mage/cookies.js</script>
</action>
<action method="addCss">
<stylesheet>css/reset.css</stylesheet>
</action>
<action method="addCss">
<stylesheet>css/boxes.css</stylesheet>
</action>
<action method="addCss">
<stylesheet>css/clears.css</stylesheet>
</action>
<action method="addCss">
<stylesheet>css/menu.css</stylesheet>
</action>
<action method="addCss">
<stylesheet>css/calendar-blue.css</stylesheet>
</action>
<action method="addCss">
<stylesheet>css/styles.css</stylesheet>
</action>
<action method="addItem">
<type>skin_css</type>
<name>css/iestyles.css</name>
<params/>
<if>IE</if>
</action>
<action method="addItem">
<type>skin_css</type>
<name>css/ie7.css</name>
<params/>
<if>IE 7</if>
</action>
<action method="addItem">
<type>skin_css</type>
<name>css/ie7minus.css</name>
<params/>
<if>lt IE 7</if>
</action>
<action method="addItem">
<type>js</type>
<name>lib/ds-sleight.js</name>
<params/>
<if>lt IE 7</if>
</action>
<action method="addItem">
<type>js</type>
<name>varien/iehover-fix.js</name>
<params/>
<if>lt IE 7</if>
</action>
<action method="addCss">
<stylesheet>css/print.css</stylesheet>
<params>media="print"</params>
</action>
</block>
<block type="page/html_header" name="header" as="header">
<block type="page/template_links" name="top.links" as="topLinks"/>
<block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
<block type="core/template" name="top.nav" template="page/html/top.nav.phtml"/>
</block>
<block type="core/messages" name="global_messages" as="global_messages"/>
<block type="core/messages" name="messages" as="messages"/>
<block type="core/text_list" name="content" as="content"/>
<block type="core/text_list" name="right" as="right"/>
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml"/>
<block type="core/text_list" name="before_body_end" as="before_body_end"/>
</block>
<block type="core/profiler" output="toHtml"/>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer">
<label>My Account</label>
<url helper="customer/getAccountUrl"/>
<title>My Account</title>
<prepare/>
<urlParams/>
<position>10</position>
</action>
</reference>
<reference name="root">
<action method="setTemplate">
<template>page/2columns-left.phtml</template>
</action>
</reference>
<reference name="top.menu">
<block type="catalog/navigation" name="catalog.topnav" template="catalog/navigation/top.phtml"/>
</reference>
<reference name="footer_links">
<action method="addLink" translate="label title" module="catalog" ifconfig="catalog/seo/site_map">
<label>Site Map</label>
<url helper="catalog/map/getCategoryUrl"/>
<title>Site Map</title>
</action>
</reference>
<reference name="footer_links">
<action method="addLink" translate="label title" module="catalogsearch" ifconfig="catalog/seo/search_terms">
<label>Search Terms</label>
<url helper="catalogsearch/getSearchTermUrl"/>
<title>Search Terms</title>
</action>
<action method="addLink" translate="label title" module="catalogsearch">
<label>Advanced Search</label>
<url helper="catalogsearch/getAdvancedSearchUrl"/>
<title>Advanced Search</title>
</action>
</reference>
<reference name="top.links">
<block type="checkout/links" name="checkout_cart_link">
<action method="addCartLink"/>
<action method="addCheckoutLink"/>
</block>
</reference>
<reference name="footer">
<block type="cms/block" name="cms_footer_links" before="footer_links">
<action method="setBlockId">
<block_id>footer_links</block_id>
</action>
</block>
</reference>
<reference name="left">
<block type="tag/popular" name="tags_popular" template="tag/popular.phtm" ignore="1">
<action method="setTemplate">
<template>tag/popular.phtml</template>
</action>
</block>
</reference>
<reference name="left">
</reference>
<reference name="before_body_end">
<block type="googleanalytics/ga" name="google_analytics" as="google_analytics"/>
</reference>
<reference name="footer_links">
<action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled">
<label>Contact Us</label>
<url>contact-us</url>
<title>Contact Us</title>
<prepare>true</prepare>
</action>
</reference>
<reference name="footer_links">
<action method="addLink" translate="label title" module="rss" ifconfig="rss/config/active">
<label>RSS</label>
<url>rss</url>
<title>RSS testing</title>
<prepare>true</prepare>
<urlParams/>
<position/>
<li/>
<a>class="link-feed"</a>
</action>
</reference>
<reference name="wishlist_sidebar">
<action method="addPriceBlockType">
<type>bundle</type>
<block>bundle/catalog_product_price</block>
<template>bundle/catalog/product/price.phtml</template>
</action>
</reference>
<reference name="cart_sidebar">
<action method="addItemRender">
<type>bundle</type>
<block>bundle/checkout_cart_item_renderer</block>
<template>checkout/cart/sidebar/default.phtml</template>
</action>
</reference>
<reference name="root">
<action method="setTemplate">
<template>page/2columns-left.phtml</template>
</action>
</reference>
<reference name="left">
<action method="unsetChild">
<name>catalog.navigation.all</name>
</action>
<action method="unsetChild">
<name>callout.sendcard</name>
</action>
<action method="unsetChild">
<name>callout.specialorder</name>
</action>
<block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
<action method="addLink" translate="label" module="customer">
<name>account</name>
<path>customer/account/</path>
<label>Account Dashboard</label>
</action>
<action method="addLink" translate="label" module="customer">
<name>account_edit</name>
<path>customer/account/edit/</path>
<label>Account Information</label>
</action>
<action method="addLink" translate="label" module="customer">
<name>address_book</name>
<path>customer/address/</path>
<label>Address Book</label>
</action>
</block>
<block type="sales/reorder_sidebar" name="sale.reorder.sidebar" as="reorder" template="sales/reorder/sidebar.phtml"/>
<remove name="tags_popular"/>
</reference>
<reference name="customer_account_navigation">
<action method="addLink" translate="label" module="sales">
<name>orders</name>
<path>sales/order/history/</path>
<label>My Orders</label>
</action>
</reference>
<reference name="customer_account_navigation">
<action method="addLink" translate="label" module="tag">
<name>tags</name>
<path>tag/customer/</path>
<label>My Tags</label>
</action>
</reference>
<reference name="customer_account_navigation">
<action method="addLink" translate="label" module="newsletter">
<name>newsletter</name>
<path>newsletter/manage/</path>
<label>Newsletter Subscriptions</label>
</action>
</reference>
<reference name="cart_sidebar">
<action method="addItemRender">
<type>bundle</type>
<block>bundle/checkout_cart_item_renderer</block>
<template>checkout/cart/sidebar/default.phtml</template>
</action>
</reference>
<update handle="customer_account"/>
<reference name="content">
<block type="customer/account_dashboard" name="customer_account_dashboard" template="customer/account/dashboard.phtml">
<block type="customer/account_dashboard_hello" name="customer_account_dashboard_hello" as="hello" template="customer/account/dashboard/hello.phtml"/>
<block type="core/template" name="customer_account_dashboard_top" as="top"/>
<block type="customer/account_dashboard_info" name="customer_account_dashboard_info" as="info" template="customer/account/dashboard/info.phtml"/>
<block type="customer/account_dashboard_newsletter" name="customer_account_dashboard_newsletter" as="newsletter" template="customer/account/dashboard/newsletter.phtml"/>
<block type="customer/account_dashboard_address" name="customer_account_dashboard_address" as="address" template="customer/account/dashboard/address.phtml"/>
<block type="core/template" name="customer_account_dashboard_info1" as="info1"/>
<block type="core/template" name="customer_account_dashboard_info2" as="info2"/>
</block>
</reference>
<reference name="right">
<action method="unsetChild">
<name>catalog_compare_sidebar</name>
</action>
</reference>
<reference name="customer_account_dashboard">
<action method="unsetChild">
<name>top</name>
</action>
<block type="sales/order_recent" name="customer_account_dashboard_top" as="top" template="sales/order/recent.phtml"/>
</reference>
<reference name="right">
<action method="unsetChild">
<name>right.poll</name>
</action>
</reference>
<reference name="customer_account_dashboard">
<action method="unsetChild">
<name>customer_account_dashboard_info2</name>
</action>
<block type="tag/customer_recent" name="customer_account_dashboard_info2" as="info2" template="tag/customer/recent.phtml"/>
</reference>
<reference name="right">
<action method="unsetChild">
<name>right.newsletter</name>
</action>
</reference>
<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></layout>
回答by Alan Storm
First things first. Make sure you've cleared out your Magento application cache. All layout XML is cached by Magento, so dropping a new file in there isn't enough to trigger any changes.
先说第一件事。确保您已清除 Magento 应用程序缓存。所有布局 XML 都由 Magento 缓存,因此将新文件放入其中并不足以触发任何更改。
It sounds like your left hand column isn't rendering. Here's a few possible reasons for this
听起来你的左手栏没有渲染。这里有几个可能的原因
Your root template to is being set to something other than the two column left layout
A <remove /> tag is being injected into the layout somewhere that's zapping your left column
Your "left" block is being overridden so that it doesn't have the child blocks it needs to properly render
您的根模板设置为两列左侧布局以外的其他内容
一个 <remove /> 标签被注入到布局中的某个地方,它正在移动你的左列
您的“左”块被覆盖,因此它没有正确呈现所需的子块
So, step 1 is to figure out which of the three this is. Place some arbitrary but noticeable text in all your php/phtml files (i tend towards something like <h1>one</h1>, <h1>two</h1>, etc.) so you can tell which files are actuallybeing loaded.
所以,第一步是弄清楚这是三个中的哪一个。在你所有的 php/phtml 文件中放置一些任意但引人注目的文本(我倾向于像 <h1>one</h1>、<h1>two</h1> 等)这样你就可以知道哪些文件实际上正在加载.
There's also a template debug setting in
还有一个模板调试设置
System->Configuration->Developer->Debug->Template Path Hints
which does something similar. If you want to use this you'll need to drill down to a specific configuration scope (you can't set it on default)
它做了类似的事情。如果您想使用它,您需要深入到特定的配置范围(您不能将其设置为默认值)
While doing either of these won't point to the direct problem, they will (hopefully) let you rule out individual causes.
虽然执行这些操作中的任何一个都不会指向直接问题,但它们会(希望)让您排除个别原因。
There's an important thing to keep in mind about layouts. The names of those XML files are arbitrary. They way layouts work is allthe layout XML is combined into one giant XML file. Then, for each request, this large XML file is reduced depending on what "handles" a page request has. A handle is something like <default> or <checkout_cart_index>. In other words, something in any of your other layout files may be causing you problems on the checkout page, notjust things in customer.xml.
关于布局,有一件重要的事情要记住。这些 XML 文件的名称是任意的。他们的布局工作方式是将所有布局 XML 组合成一个巨大的 XML 文件。然后,对于每个请求,这个大型 XML 文件会根据页面请求“处理”的内容而减少。句柄类似于 <default> 或 <checkout_cart_index>。换句话说,您的任何其他布局文件中的某些内容可能会导致结帐页面出现问题,而不仅仅是 customer.xml 中的内容。
It's also possible that the Magento site you're working with has a controller or two that's overridden, which would change the layout handles that Magento looks for with any page request.
您正在使用的 Magento 站点也可能有一个或两个被覆盖的控制器,这将更改 Magento 使用任何页面请求查找的布局句柄。
Point being, there's a number of things that could be causing this, and we need to peek inside Magento's internals. Install this module in your development environment (it's an experimental debugging thing I'm working on)
关键是,有很多事情可能会导致这种情况,我们需要深入了解 Magento 的内部结构。在你的开发环境中安装这个模块(这是我正在做的实验性调试)
http://alanstorm.com/2005/projects/Layoutviewer.tar.gz
http://alanstorm.com/2005/projects/Layoutviewer.tar.gz
When you have it up and running, load a page in your store with the following query string
启动并运行后,使用以下查询字符串在商店中加载页面
http://magento.example.com/customer/account/?showLayout=handles
This will display the handles magento uses on any request. You should see a list of something like
这将显示 magento 在任何请求上使用的句柄。你应该看到一个类似的列表
- default
- STORE_bare_us
- THEME_\frontend_default_default
- customer_account_index
- customer_logged_in
- 默认
- STORE_bare_us
- THEME_\frontend_default_default
- customer_account_index
- customer_logged_in
If number 4 is something different (companyname_modulename_customer_account_index), that means your site has a custom controller for this request. If that's the case, you'll want to look for tags in your layouts inside <companyname_modulename_customer_account_index> that may be overriding what you want to do.
如果数字 4 有所不同(companyname_modulename_customer_account_index),则意味着您的站点具有针对此请求的自定义控制器。如果是这种情况,您将需要在 <companyname_modulename_customer_account_index> 内的布局中查找可能覆盖您想要执行的操作的标记。
Next, load a Magento URL with the following query string
接下来,使用以下查询字符串加载 Magento URL
http://magento.example.com/customer/account/?showLayout=page
You should see an XML file being rendered in the browser. This is you request's final layout XML. Look for a tag (most likely named root) with an output attribute set
您应该会看到一个 XML 文件正在浏览器中呈现。这是您请求的最终布局 XML。查找带有输出属性集的标签(最有可能命名为 root)
<block type="page/html" name="root" output="toHtml" template="page/2columns-left.phtml">
The output attribute means this is the template that Magento will start rendering with. If this isn't your two column layout, you're closer to solving your problem.
output 属性意味着这是 Magento 将开始渲染的模板。如果这不是您的两列布局,那么您离解决问题更近了。
Next, look for a module named left inside the root module
接下来,在根模块中查找名为 left 的模块
<block type="core/text_list" name="left" as="left" ignore="1"/>
If this has an ignore attribute, there will probably be a corresponding tag
如果这个有一个ignore属性,可能会有一个对应的标签
<remove name="left"/>
somewhere in your layout. You'll want to remove this.
在您的布局中的某个地方。你会想要删除它。
Also, make sure that your root block actually has a child block with the name left.
另外,请确保您的根块实际上有一个名称为 left 的子块。
<block type="page/html" name="root" output="toHtml" ... >
...
<block type="core/text_list" name="left" as "left" />
...
</block>
Finally, and this is more a sanity check
最后,这更像是一次健全性检查
http://magento.example.com/checkout/cart/?showLayout=package
Specifying "package" in the showLayout query string parameter will show you your entirepackage layout. This is all your layout.xml files combined into one. You can use this to make sure magento knows about the XML you're adding (cache), and to make sure you're editing the correct files. You can also example each handle section to look for unexpected layout intrusctions that are giving you the results you're not happy with.
在 showLayout 查询字符串参数中指定“package”将显示您的整个包布局。这就是您所有的 layout.xml 文件合二为一。您可以使用它来确保 magento 知道您正在添加的 XML(缓存),并确保您正在编辑正确的文件。您还可以对每个句柄部分进行示例,以查找意外的布局干扰,这些干扰会给您带来不满意的结果。
回答by Del F
In response to dolu (for anyone else who has this problem), if you put Alan's module in app/code/community, you need to edit app/etc/modules/Alanstormdotcom_Layoutviewer.xml to use the "community" codePool. The module expects to be installed at app/code/local by default (at least the version linked to Alan's answer here).
针对dolu(针对其他有此问题的人),如果您将Alan 的模块放在app/code/community 中,则需要编辑app/etc/modules/Alanstormdotcom_Layoutviewer.xml 以使用“community”codePool。该模块预计默认安装在 app/code/local (至少是链接到 Alan 的答案here 的版本)。

