xml - Magento我的帐户布局XML问题

标签 xml layout magento php

我在使customer.xml布局文件对于客户的“我的帐户”页面正常工作时遇到问题。

导航链接和通常位于页面左侧的先前订购的项目不会显示在页面上,但是如果我在xml文件中将引用名称更改为“content”,则会显示出来(除非它是显然是在右侧)。我已经检查了它所引用的模板(2columns-left.phtml),并且getChildHtml('left')在正确的位置。

导致问题的块:

<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>

这基本上是从我们的另一个网站上直接复制过来的,该网站可以100%正常工作。我已经尝试了所有我能想到的一切(例如,在模板和布局xml中都更改了引用的名称)无济于事。布局所引用的模板显然可以正常工作,因为当它们放入“内容”区域时,它们确实会显示出来。

magento的此安装为1.3.1.1版。

我感谢您给我的任何建议...

更新:我尝试将引用更改为“global_messages”,但也未显示该引用。它似乎仅在“内容”部分中起作用。

更新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>

最佳答案

首先是第一件事。确保您已经清除了Magento应用程序缓存。 Magento缓存了所有布局XML,因此,在其中放置新文件不足以触发任何更改。

听起来您的左手列未渲染。这是一些可能的原因

  • 您的根模板将被设置为左两列布局之外的其他内容
  • 一个标记被注入(inject)到布局中,这会改变您的左列
  • 您的“left”块被覆盖,因此它没有正确渲染
  • 所需的子块

    因此,步骤1是找出这三个中的哪个。在您的所有php/phtml文件中放置一些任意但引人注目的文本(我倾向于使用

    one

    two

    等),这样您就可以分辨出哪些文件是实际上是正在加载。

    还有一个模板调试设置
    System->Configuration->Developer->Debug->Template Path Hints
    

    做类似的事情。如果要使用此功能,则需要向下钻取到特定的配置范围(无法将其设置为默认值)

    尽管执行上述任何一项操作都不会指出直接的问题,但它们(希望)可以让您排除个别原因。

    关于布局,有一件重要的事情要牢记。这些XML文件的名称是任意的。布局工作的方式是所有,布局XML被组合到一个巨大的XML文件中。然后,对于每个请求,将根据页面请求具有的“句柄”来缩减此大型XML文件。句柄类似于。换句话说,任何其他布局文件中的内容都可能导致您在结帐页面上出现问题,而不是只是customer.xml中的内容。

    您正在使用的Magento站点也可能有一个或两个被覆盖的 Controller ,这将更改Magento在任何页面请求中查找的布局句柄。

    关键是,有许多原因可能导致了这一点,我们需要窥探Magento的内部。在您的开发环境中安装此模块(这是我正在从事的实验性调试工作)

    http://alanstorm.com/2005/projects/Layoutviewer.tar.gz

    启动并运行后,使用以下查询字符串在商店中加载页面
    http://magento.example.com/customer/account/?showLayout=handles
    

    这将显示magento在任何请求上使用的句柄。您应该会看到类似以下内容的列表
  • 默认
  • STORE_bare_us
  • THEME_\frontend_default_default
  • customer_account_index
  • customer_logged_in

  • 如果数字4有所不同(companyname_modulename_customer_account_index),则意味着您的站点具有针对此请求的自定义 Controller 。在这种情况下,您需要在布局中的中查找可能会覆盖您想要做的事情的标签。

    接下来,使用以下查询字符串加载Magento URL
    http://magento.example.com/customer/account/?showLayout=page
    

    您应该看到浏览器中正在渲染一个XML文件。这是您请求的最终布局XML。查找带有输出属性集的标签(最有可能命名为根)
    <block type="page/html" name="root" output="toHtml" template="page/2columns-left.phtml">
    

    输出属性意味着这是Magento将开始渲染的模板。如果这不是您的两列布局,那么您就更接近解决问题了。

    接下来,在根模块中查找名为left的模块
    <block type="core/text_list" name="left" as="left" ignore="1"/>
    

    如果它具有ignore属性,则可能会有一个对应的标签
    <remove name="left"/>
    

    在您的布局中的某处。您将要删除它。

    另外,请确保您的根块实际上有一个名称为左的子块。
    <block type="page/html" name="root" output="toHtml" ... >
        ...
        <block type="core/text_list" name="left" as "left" />
        ...
    </block>
    

    最后,这更是一个健全的检查
    http://magento.example.com/checkout/cart/?showLayout=package
    

    在showLayout查询字符串参数中指定“包”将显示整个包的布局。这是所有您的layout.xml文件组合在一起的文件。您可以使用它来确保magento知道要添加的XML(缓存),并确保您正在编辑正确的文件。您也可以在每个句柄部分进行示例,以查找意外的布局指令,这些指令会给您带来您不满意的结果。

    关于xml - Magento我的帐户布局XML问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1087733/

    相关文章:

    css - webkit - css 样式不起作用

    iphone - 在 Objective-C 中动态实例化类,可能吗?

    java - 尝试运行使用绝对布局的 JAR 时出现 NoClassDefFoundError

    java - 通过拖动角来调整 gui 元素的大小

    mysql - magento 可以使用多个 MySQL 从站吗?

    php - Magento 1.9 无法保存追加销售/相关/交叉销售产品

    XMLStarlet:如何选择 XML,返回空

    xml - R devtools 失败为 "Package libxml-2.0 was not found in the pkg-config search path"

    java - XSD 架构中需要什么来生成 @XmlElementDecl 方法?

    html - 无法摆脱内联 block 元素之间的空格