cancel
Showing results for 
Search instead for 
Did you mean: 

how to dispalay created blocks and pages in magento 2 frontend

how to dispalay created blocks and pages in magento 2 frontend

hi guys , i created blocks and pages through admin and i selected website to display the content.But i could not see any reflections in frontend. can any one help me ?

5 REPLIES 5

Re: how to dispalay created blocks and pages in magento 2 frontend

@bharath553

 

Display CMS Static Block In Phtml File:

Here the code to show CMS Static Block in any template (phtml) file in Magento 2,

<?php
    echo $block->getLayout()
               ->createBlock('Magento\Cms\Block\Block')
               ->setBlockId('block_identifier')
               ->toHtml();
?>

Display CMS Static Block In CMS Page:

Here the code to show CMS Static Block in any other CMS static page in Magento 2,

 

{{block class="Magento\Cms\Block\Block" block_id="block_identifier"}}
 

Display CMS Static Block In XML:

Here the code to show CMS Static Block in any layout (XML) file in Magento 2,

<referenceContainer name="content">
    <block class="Magento\Cms\Block\Block" name="block_identifier">
        <arguments>
            <argument name="block_id" xsi:type="string">block_identifier</argument>
        </arguments>
    </block>
</referenceContainer>
 

Hope this helps.

 

CMS>page, you can directly call by url: Content>pages>find Url key, add this url key directly in site url i.e. example.com/url-key

Manish Mittal
https://www.manishmittal.com/

Re: how to dispalay created blocks and pages in magento 2 frontend

{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}
I given same syntax in pages but it's not showing any content in frontend

Re: how to dispalay created blocks and pages in magento 2 frontend

this is what i given :

{{block class="Magento\\Cms\\Block\\Block" block_id="N_id2-N_block2"}}

 

Re: how to dispalay created blocks and pages in magento 2 frontend

{{block class="Magento\Cms\Block\Block" block_id="block_identifier"}}

try this

Manish Mittal
https://www.manishmittal.com/

Re: how to dispalay created blocks and pages in magento 2 frontend

@bharath553

 

Content > edit home page > Click on Show/ Hide editor > add content {{block class="Magento\Cms\Block\Block" block_id="test"}} Save. It should work now.

Manish Mittal
https://www.manishmittal.com/