I want to add a config
field to my magento instance. You should be able to store a cms block in it.
<block translate="label">
<label>Cms block</label>
<frontend_type>select</frontend_type>
<source_model>???</source_model>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</block>
But I only found the model for cms pages (adminhtml/system_config_source_cms_page
).
What is the corresponding source_model
for cms blocks?
CMS blocks allow you to share some information with your customers, announce special offers, sales, dicounts or just make your Magento 2 store pages more interesting and engaging.
You can get CMS Static Blocks collection by an identifier in Magento 2 by calling BlockRepositoryInterface interface. Magento\Cms\Api\BlockRepositoryInterface used for getting CMS Static Blocks in Magento 2.
Login to Magento 2, move to Content –> Blocks. Click “Add New Block“, add below information and save configuration. Enable Block: Enable the block. Block Title: Name of the block to easily identify the purpose of creating the block.
login to magento admin. Open any cms page and write block code in content section. After using the block code phtml file will be called on cms page. If you want to call phtml file on all cms pages then you can create a layout file to achieve this.
I think class Mage_Cms_Model_Resource_Block_Collection works great for this:
<cms_block translate="label">
<label>Left template CMS block</label>
<frontend_type>select</frontend_type>
<source_model>cms/resource_block_collection</source_model>
<sort_order>0</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
</cms_block>
There aren't any, but you can make yours :
class Your_Module_Model_System_Config_Source_Cms_Block
{
protected $_options;
public function toOptionArray()
{
if (!$this->_options) {
$this->_options = Mage::getResourceModel('cms/block_collection')
->load()
->toOptionArray();
}
return $this->_options;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With