How to call static block in magento2

Home / Magento2 / How to call static block in magento2

Creating static block Magento2

=> Login in into your magento2 development admin panel.
=> Navigate to Content->Blocks
=> Click Add New Block
=> Give your block title (Title: A descriptive name to identify this block)
=> Give your block identifier (Identifier: The identifier will allow you to call this block from your template files or using the Magento markup tags. Typically this would be a programmer-friendly name with no spaces or punctuation ie “my_block_identifier” rather than “My block’s identifier!”)
=> Set status enabled (Status: Here you can enable or disable a block.)
=> Enter your block content field (Content: As well as standard HTML you can also include special Magento markup tags in the block content. You can find information about these tags on the markup tags wiki page.)
=> Click Save Block or Save and Continue Edit to save your settings.

How to call image in static block

{{media url="wysiwyg/exclusive-icon.jpg"}}

How to create a link to another page within your site

{{config path="web/unsecure/base_url"}}

How to call static block any XML file

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

How to call static block in your template or .phtml files

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

How to call static block in CMS->Pages

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

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *