【问题标题】:Transfer the block from right-sidebar to main content将块从右侧栏转移到主要内容
【发布时间】:2015-08-13 05:53:57
【问题描述】:

我正在使用 magento 1.8.1 并且我安装了一个扩展程序,即 checkdelivery。但在前端,他们的块显示在右侧栏中,但我不希望该页面上的右侧栏。那么我如何将该块从右侧边栏转移到主要内容。

他们的 Phtml 文件:

    <div class="block block-list block-check-delivery">
<div class="block-title">
    <?php $blockLabel = Mage::getStoreConfig('checkdelivery/general/block_title'); ?>
    <strong><span><?php echo $this->__($blockLabel) ?></span></strong>
</div>
<div class="block-content" >        
    <br>
        <input name="zipcode" size="17" type="text" id="zipcode" maxlength="10" class="input-text" placeholder="<?php echo $this->__('Enter ZIP Code'); ?>"/>
        <button type="button" name="zip-check" title="Check" class="button" id="zip-check" ><span><?php echo $this->__('Check'); ?></span></button>
        <div id="delivery-message"></div>
        <?php $defaultHtml = Mage::getStoreConfig('checkdelivery/general/default_html'); ?>
        <div id="delivery-html"><?php echo $defaultHtml ?></div>

    <br>        
</div>

和 Ajax 代码:

  <script>
Event.observe('zip-check', 'click', function(event){
    new Ajax.Request("<?php echo $this->getUrl('checkdelivery/index/index') ?>", {
        method: "get",
        parameters: {zipcode : $('zipcode').value },
        onSuccess: function(transport) {
             var json = transport.responseText.evalJSON();
             $('delivery-message').update(json.message);                 
             $('delivery-message').setStyle({ color: json.color});
             $('delivery-html').update(json.html);  
        }
    });
});

layout.xml

   <layout version="0.1.0">

<catalog_product_view>
    <reference name="right" > 
        <block type="checkdelivery/checkdelivery" before="-" name="checkdelivery"> 
            <action method="setTemplate" ifconfig="checkdelivery/general/active">
                <template>checkdelivery/checkdelivery.phtml</template>
            </action>
        </block>
    </reference> 
</catalog_product_view>
<catalog_product_view>
    <block type="checkdelivery/checkdelivery" before="-" name="checkdelivery"> 
        <action method="setTemplate" ifconfig="checkdelivery/general/active">
            <template>checkdelivery/checkdelivery.phtml</template>
        </action> 
    </block>
</catalog_product_view>

【问题讨论】:

  • 向我们展示相关代码。没有它,我们无法帮助您......谢谢
  • 现在我把phtml代码和ajax代码都放了
  • 显示该扩展使用的布局 xml 文件。抱歉,如果不清楚。 phtml 文件不会帮助我们找出确切的块
  • 是的,我放了布局文件

标签: php magento frontend magento-1.8 magento-1.9


【解决方案1】:

如下更新你的布局

<catalog_product_view>
  <reference name="content">
    <block type="checkdelivery/checkdelivery" name="checkdelivery" as="checkdelivery"> 
        <action method="setTemplate" ifconfig="checkdelivery/general/active">
            <template>checkdelivery/checkdelivery.phtml</template>
        </action> 
    </block>
  </reference>  
</catalog_product_view>

并调用 product/view.phtml 中的块,如下所示:

echo $this->getChildHtml('checkdelivery')

【讨论】:

  • 嘿,它在本地主机上工作正常,但是当我在服务器上使用相同的编码时,它不显示在前端,为什么?
【解决方案2】:

在您的 local.xml 文件中使用它。

<layout>
    <catalog_product_view>
        <remove name="checkdelivery" />
        <reference name="content">
            <block type="checkdelivery/checkdelivery" name="checkdelivery">
                <action method="setTemplate" ifconfig="checkdelivery/general/active">
                    <template>checkdelivery/checkdelivery.phtml</template>
                </action>
            </block>
        </reference>
    </catalog_product_view>
</layout>

然后像这样在view.phtml 中调用你的块。

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

【讨论】:

  • 您需要在view.phtml 文件中调用您的块,正如 pankaj 指出的那样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-19
  • 1970-01-01
  • 2014-12-01
相关资源
最近更新 更多