I have created many blocks but as far as I know only by exporting them from database is the only way to have their code. Is there another way to have the files? because pushing and commiting .sql to rep is not the best practice.


3 Answers 3


If you want to use best practice, you may look at the core cms module in Magento:

For instance: the function \Magento\Cms\Setup\Patch\Data\CreateDefaultPages::apply shows a way to add cms assets in the database.

Specifically, I do like this format shown in the screenshot below:

enter image description here


Well cms_block is a table and all is stored in the database fields. Why you you want to have them in a file ?

If you want to have a block content in a file, then what you need is to directly write the html code in a template and not using the block anymore.

If what you need is for some reason to get your block content in a file; you might want to create a command that will read cms_block and do it for yourself without going through sql.

  • the thing is that updating the file everytime the block is changed and pushing it to rep is a little bit tricky. I wanted to know if there is something like the composer.json where you have the modules. Oct 8, 2020 at 15:17
  • What is that file you are refering to ? There shouldn't be any files for cms block.
    – Claims
    Oct 8, 2020 at 15:27

Just so you know it is actually doable to add a cms content via hard code that saves the data you created every time you deploy. Sadly I can't explain further as I don't really know the logic behind the module created by one of our backend (I am frontend) and I can't really share the module due to company policies. Your best bet is to buy an extension cms content uploader.

Sorry if this is not much of a help.

  • thanks, everything is helpful! Oct 13, 2020 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.