panggilan blok statis di view.phtml insted file phtml


14

kami menampilkan bidang teks di halaman tampilan untuk memeriksa ketersediaan COD.

masukkan deskripsi gambar di sini

view.phtml

echo $this->getLayout()->createBlock('core/template')->setTemplate('checkdelivery/checkdelivery.phtml')->toHtml();

di view.phtmlkami memanggil file di bawah ini. tetapi saya ingin memanggil pengidentifikasi blok statis [kode pengidentifikasi - periksa] daripada file di bawah ini.

template / checkdelivery / 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" value="<?php echo Mage::getModel('core/cookie')->get('zip'); ?>" 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 if(Mage::getModel('core/cookie')->get('message')){
    echo Mage::getModel('core/cookie')->get('message');
}
else{
    $defaultHtml; } ?></div>

        <br>        
    </div>

</div>

<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);  
            }
        });
    });
</script>

kode blok statis:

<p>{{block type ="core/template" template = "checkdelivery/checkdelivery.phtml"}}</p>

Jawaban:


44

Anda dapat menggunakan kode di bawah ini:

dalam file .phtml:

<?php
  echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml(); 
?> 

Sampel :

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('home')->toHtml(); ?> 

di halaman blok / cms statis:

{{block type="core/template" template="checkdelivery/checkdelivery.phtml"}}


itu tidak menampilkan bidang teks sekarang. saya memperbarui kode blok statis yang dimaksud.
— Baby in Magento

apakah Anda menyegarkan cache?
— Qaisar Satti

ya folder cache yang dihapus, cache browser juga dihapus.
— Bayi di Magento

1
{{block type ="core/template" template="checkdelivery/checkdelivery.phtml" }}hapus spasi dan periksa system->permission ->blockapakah sudah terdaftar (core / template)?
— Qaisar Satti

1
createBlock ('Magento \ Cms \ Block \ Block') alih-alih -> createBlock ('cms / block') wordked untuk saya :) Terima kasih atas tip ini!
— Rustyjim

3

Jika Anda telah membuat blok CMS bernama 'block_identifier' dari panel admin. Maka berikut ini akan menjadi kode untuk memanggil mereka dalam .phtml

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml(); 
?> 

Bersihkan cache dan muat ulang browser Anda.

Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.