【问题标题】:Magento::Custom Block not working in HomepageMagento::Custom Block 在主页中不起作用
【发布时间】:2014-08-05 06:31:24
【问题描述】:

在 magento 中,我只想在主页中显示一个静态块。

我尝试了this question 中提到的解决方案,但没有奏效。

我在 page.xml 文件中添加了这段代码,但它开始出现错误,所以我将其从它们中删除并将其放入 local.xml 文件中:

<cms_index_index>
  <reference name="content">
    <block type="cms/block" name="home-page-block">
      <action method="setBlockId"><block_id>home-page-block</block_id></action>
    </block>
  </reference>
<cms_index_index>

它没有给出错误,但仍然没有显示静态块。我什至在 2columns-right.phtml 文件中输入了这个,虽然我认为这不是必需的。

<?php echo $this->getChildHtml('home-page-block') ?>

但是还是不行。有人能指出我错过了什么吗?

【问题讨论】:

    标签: magento


    【解决方案1】:
    one of the easiest thing to do is
    <?php
    $homePageUrl = Mage::getBaseUrl(); //this gets you your domain name sort of
    $currentUrl = $this->helper('core/url')->getCurrentUrl(); // this gets the current url
    
    //you can now do your conditional stuff in here
    if($currentUrl == $homePageUrl) : ?>
    
    //then display your block by calling the block 
        <div style="margin: 0 auto; width: 100%; max-width: 1180px;">
            <?php echo $this->getLayout()
                ->createBlock('cms/block')
                ->setBlockId('seo-homepage')
                ->toHtml();
            ?>
        </div>
    <?php endif; ?>
    

    【讨论】:

      【解决方案2】:

      假设您已经完成了所有清除缓存、禁用缓存的标准程序,我认为句柄应该是 cms_index_defaultindex 而不是 cms_index_index

      其次,getChildHtml() 位是正确的,因为你已经在 &lt;reference name="content" /&gt; 了。

      【讨论】:

      • 我想我把它放在了错误的文件中。我将它插入到 cms.xml 文件中:&lt;cms_index_index translate="label"&gt; 并且它起作用了
      猜你喜欢
      • 1970-01-01
      • 2015-01-21
      • 1970-01-01
      • 1970-01-01
      • 2011-10-17
      • 1970-01-01
      • 1970-01-01
      • 2012-07-27
      相关资源
      最近更新 更多