【问题标题】:Loading the content of a static block from inside a magento CMS layout?从magento CMS布局中加载静态块的内容?
【发布时间】:2015-05-09 02:18:00
【问题描述】:

如何在 CMS 布局中加载 Magento 静态块的内容?

我的目标是加载静态块 {{block type="cms/block" block_id="menu_about"}} 里面的布局,找不到如何做到这一点谁能帮助我?谢谢!

    <!DOCTYPE html>
<html lang="en">

<head>
    <?php echo $this->getChildHtml('head') ?>
</head>

<body<?php echo $this->getBodyClass() ? ' class="' . $this->getBodyClass() . '"' : '' ?>>

<div class="wrapper">

    STATIC LEFT CMS

    <div class="wrapper_header">
        <?php echo $this->getChildHtml('global_messages') ?>
        <?php echo $this->getChildHtml('header') ?>
    </div>

    <div class="container">

        <div class="menu_left col-lg-4 col-md-4">
            {{block type="cms/block" block_id="menu_about"}}
        </div>

        <div class="col-lg-8 col-md-8">
            <?php echo $this->getChildHtml('content') ?>
        </div>
    </div>

</div>
</body>
</html>

【问题讨论】:

    标签: magento layout content-management-system static-block


    【解决方案1】:
    <div class="menu_left col-lg-4 col-md-4">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('menu_about')->toHtml(); ?> 
    </div>
    

    【讨论】:

    • 这完全有效,太棒了!谢谢! Magento 时不时地把我的头发拉出来
    【解决方案2】:

    如果你愿意,你可以对页面做同样的事情。 根据您的需要自定义块 ID。

     // Insert the block into the page.
    $sBlockId = 'changeme!';
    $oBlock = Mage::getModel( 'cms/block' );
    $oBlock->setStoreId( Mage::app()->getStore()->getId() );
    $oBlock->load( $sBlockId, 'identifier' );
    $oCmsHelper = Mage::helper( 'cms' );
    $oProcessor = $oCmsHelper->getPageTemplateProcessor();
    $sHtml = $oProcessor->filter( $oBlock->getContent() );
    echo $sHtml;
    

    【讨论】:

      猜你喜欢
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-22
      • 2011-06-08
      相关资源
      最近更新 更多