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
1
|
{{media url="wysiwyg/exclusive-icon.jpg"}} |
How to create a link to another page within your site
1
|
{{config path="web/unsecure/base_url"}} |
How to call static block any XML file
1
2
3
4
5
6
7
|
<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> |
How to call static block in your template or .phtml files
1
|
<?php echo $this ->getLayout()->createBlock( 'Magento\Cms\Block\Block' )->setBlockId( 'block_identifier' )->toHtml();?> |
How to call static block in CMS->Pages
1
|
{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}} |