【问题标题】:Provide new references for static blocks in Magento layout为 Magento 布局中的静态块提供新的参考
【发布时间】:2011-06-08 14:16:02
【问题描述】:

我想在我网站的每个页面内容的顶部显示一个轮播和两个横幅。 我从 page.xml 的页脚块开始创建了一个自定义引用。 这就是它的样子:

<block type="page/html" name="topcontent" as="topcontent" template="page/html/topcontent.phtml">
    <block type="page/html_wrapper" name="topcontent.container" as="topcontentContainer" translate="label">
        <label>Page Top Content</label>
        <action method="setElementClass"><value>topcontent-container</value></action>
    </block>
    <block type="core/template" name="topcontent.book.carousel" as="topcontentCarousel" template="callouts/book-carousel.phtml"/>
    <block type="core/text_list" name="topcontent.left" as="topcontentLeft" />
    <block type="core/text_list" name="topcontent.right" as="topcontentRight" />
</block>

然后我创建了一个 topcontent.phtml 文件

<div class="topcontent-container">
    <div class="topcontent">
      <?php echo $this->getChildHtml('topcontentContainer') ?> 
      <?php echo $this->getChildHtml('topcontentCarousel') ?>
      <?php echo $this->getChildHtml('topcontentLeft') ?>
      <?php echo $this->getChildHtml('topcontentRight') ?>
    </div>
</div>

我的轮播显示正确,但是当我尝试在 topcontentLeft 或 topcontentRight 中放置一个块时,它并没有全部显示。 我认为我在块类型参数上做错了,但我不知道是什么:有人可以帮我吗? 谢谢。

【问题讨论】:

    标签: templates layout magento reference block


    【解决方案1】:

    取决于您需要在横幅中显示的内容。如果只是一些文本,您可以使用文本块:

    <block type="core/text" name="topcontent.right" as="topcontentRight">
        <action method="addText"><text>Test text</text></action>
    </block>
    

    如果您需要占位符块来显示一些 CMS 静态块内容,那么您是对的,cote/text_list 是此类块的合适类型。它获取所有嵌套块并一一渲染它们。所以接下来你需要做的是放置 cms/block 占位符,它的内容可以稍后从后端添加。总而言之,它可能看起来像:

    <block type="core/text_list" name="topcontent.right" as="topcontentRight">
        <block type="cms/block" name="topcontent.right.cms" as="topcontentRightCms">
            <action method="setBlockId"><block_id>topcontent_right_static</block_id></action>
        </block>
    </block>
    

    现在您可以使用 'topcontent_right_static' id 在管理后端创建新的静态块,它会在您输出它的地方呈现。

    【讨论】:

    • 不,我需要一个区域来放置我需要的任何东西。我想创建一个引用以允许管理员将横幅放在那里,只需发布​​一个静态块。
    • 我在查看某个模块的代码时找到了相同的解决方案。顺便说一句,感谢您的帮助!
    【解决方案2】:

    我认为问题出在 topcontentLeft 和 topcontentRight 的 @type 属性中

    type="core/text_list"  need to be changed to type="core/template"
    

    【讨论】:

    • 我已经尝试过了,但并没有解决问题。我认为核心/模板需要一个 .phtml 模板才能工作。
    • 是的,应该是带模板的
    猜你喜欢
    • 1970-01-01
    • 2015-05-09
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 2012-10-14
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    相关资源
    最近更新 更多