【问题标题】:Magento Static Block not being called from layout file未从布局文件调用 Magento 静态块
【发布时间】:2013-06-19 02:12:37
【问题描述】:

我已经修改了 local.xml 的 <cms_index_index> 标记,以便在主页加载时从数据库中提取一个静态块。但是,没有拉出静态块。我创建了一个带有标识符 mobile_home 的静态块,并且它已启用。我还尝试使用现有的、正在工作的静态块,但无济于事。怎么了?什么可以让它发挥作用?

<cms_index_index>
      <block type="cms/block" name="cms_page"><action method="setBlockId"><block_id>mobile_home</block_id></action></block>
</cms_index_index>

编辑:添加引用后,仍然不渲染:

<cms_index_index>
        <reference name="head">
            <block type="cms/block" name="cms_page"><action method="setBlockId"><block_id>mobile_home</block_id></action></block>
        </reference>
    </cms_index_index>

【问题讨论】:

    标签: xml magento content-management-system magento-1.7


    【解决方案1】:

    正在实例化块(假设正在合并此布局 XML),但需要将其添加到渲染流程中。一个快速测试是通过output 属性获取你的块并使其成为输出块:

    <cms_index_index>
        <block type="cms/block" name="cms_page" output="toHtml">
            <action method="setBlockId">
                <block_id>mobile_home</block_id>
            </action>
         </block>
    </cms_index_index>
    

    然后您可以将其添加到无模板块中,例如 content:

    <cms_index_index>
        <!-- or use reference syntax, up to you -->
        <block type="cms/block" name="cms_page" parent="content">
            <action method="setBlockId">
                <block_id>mobile_home</block_id>
            </action>
         </block>
    </cms_index_index>
    

    您还可以进入 CMS 页面的内容正文并使用块指令(或通过小部件界面插入)添加静态块:

    {{block type="cms/block" block_id="mobile_home"}}
    

    {{widget type="cms/widget_block" template="cms/widget/static_block/default.phtml" block_id="5"}}
    

    【讨论】:

    • 感谢您的回复。不幸的是,静态块仍然没有渲染!请参阅上面的编辑
    • head 块是 html 头 - 它不可见!试试content 块。
    猜你喜欢
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-25
    • 2011-06-08
    • 1970-01-01
    • 2016-03-21
    相关资源
    最近更新 更多