I am able to create CMS Static Block from admin and display it on the homepage, but is there a way to do it programmatically so I can create custom widgets(basically custom HTML/CSS) and display it on the homepage? What's the best way to go about displaying Custom HTML/CSS on the homepage programmatically? Or is modifying the Content
in Content>Pages>Home Page
is the only way?
Magento 2 – How to Create and Display Custom CMS Static Block on Homepage
magento2magento2.2magento2.2.6
Best Answer
Create InstallData.php file at
/app/code/VendorName/ModuleName/Setup/InstallData.php
Then, remove your module value from setup_module table and related table also. Now, execute this below command.
Then, go to admin -> Content -> Blocks and find your static block will be created. Now, add your changes if you need.
Hope, it will helpful for you.