【问题标题】:Magento new page templateMagento 新页面模板
【发布时间】:2012-10-23 22:03:13
【问题描述】:

我正在尝试添加一个新模板,以便可以并排放置两个内容块。例如:content_left 和 content_right。问题是新字段是空的,我无法在其中显示任何内容。目标是同时登录和创建帐户,每个都有自己的块。

这是新模板 2columns.phtml(修剪了一些):

<?php echo $this->getChildHtml('head') ?>
</head>
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
<?php echo $this->getChildHtml('after_body_start') ?>
<div class="wrapper">
    <?php echo $this->getChildHtml('global_notices') ?>
    <div class="page">
        <?php echo $this->getChildHtml('header') ?>
        <div class="main-container col2-right-layout">
            <div class="main">
                <?php echo $this->getChildHtml('breadcrumbs') ?>
                <div class="col-main1">
                    <?php echo $this->getChildHtml('global_messages') ?>
                    <?php echo $this->getChildHtml('content_left') ?>
                </div>
                <div class="col-main2"><?php echo $this->getChildHtml('content_right') ?></div>
            </div>
        </div>
        <?php echo $this->getChildHtml('footer') ?>
        <?php echo $this->getChildHtml('before_body_end') ?>
    </div>
</div>
<?php echo $this->getAbsoluteFooter() ?>

这是我尝试使用的 XML:

<customer_account_login translate="label">
        <label>Customer Account Login Form</label>
        <!-- Mage_Customer -->
        <remove name="right"/>
        <remove name="left"/>

        <reference name="root">
            <action method="setTemplate"><template>page/2columns.phtml</template></action>
       </reference>
        <reference name="content_left">
            <block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
                <block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" translate="label">
                    <label>Form Fields Before</label>
                </block>
            </block>
       </reference>
        <reference name="content_right">
            <block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml" />
        </reference>
    </customer_account_login>

除了 content_left 和 content_right 似乎一切都正常。不幸的是,这需要展示所有重要的东西。我尝试更新 CSS,并在模块中定义了它。问题是使用“content_left/right”而不是“content”和其他已经使用过的东西吗?请帮忙,我整天都在这个页面上。

【问题讨论】:

    标签: templates magento


    【解决方案1】:

    你需要做几件事:

    1. 创建 content_leftcontent_right 块,而不是引用它们。它们实际上并不存在于布局文件中的任何位置,这就是为什么引用它们不起作用的原因。这需要在您向它们添加其他块之前完成。
    2. 确保创建的 content_leftcontent_right 块创建在正确的位置。通过简单地更改对块的引用,您将在与根块相同的级别创建它们......如果它们被放置在这里,它们将不会呈现。所以你需要将它们添加到根块中。

    这是我能够使用的布局:

    <customer_account_login translate="label">
        <label>Customer Account Login Form</label>
        <!-- Mage_Customer -->
        <remove name="right"/>
        <remove name="left"/>
    
        <reference name="root">
            <action method="setTemplate"><template>page/2column-contact.phtml</template></action>
    
            <block type="core/text_list" name="content_left" as="content_left" translate="label">
                <block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
                    <block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" translate="label">
                        <label>Form Fields Before</label>
                    </block>
                </block>
            </block>
    
            <block type="core/text_list" name="content_right" as="content_right" translate="label">
                <block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml" />
            </block>
        </reference>
    </customer_account_login>
    

    【讨论】:

      【解决方案2】:

      您遇到此问题的原因是您需要添加“block”而不是“reference”。

      屏蔽

      这附在每个模板上,赋予它完成工作所需的功能。

      参考

      这是一种将块(或其他规则)附加到特定页面的方法(例如,将特殊块添加到产品视图页面)。

      要解决此问题,请替换此行:

      <reference name="content_left">
      

      与:

      <block type="catalog/product" template="path/to/your/template.phtml">
      

      如果在手边,您的意图是将所有内容放在一列中 - (即,您希望将“customer_form_register”和“customer.form.register.fields.before”输出到一列,并且“ customer_form_login' 进入另一列)

      然后执行以下操作:

      1) 删除您添加的 2 个“引用”。

      2) 在 phtml 文件中创建一个 div(为您想要的每个部分)。

      3) 在这些 div 中回显块名称(即 customer_form_login)并添加必要的 CSS 规则。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-09
        • 1970-01-01
        • 1970-01-01
        • 2016-03-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多