Question

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.

Greetings!

Was it helpful?

Solution

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top