{"id":380856,"date":"2023-05-10T09:17:24","date_gmt":"2023-05-10T09:17:24","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=380856"},"modified":"2023-05-15T06:07:39","modified_gmt":"2023-05-15T06:07:39","slug":"save-a-custom-cms-block-from-frontend-in-magento-2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/","title":{"rendered":"Saving custom CMS block from frontend in Magento 2"},"content":{"rendered":"\n<p>In this blog, we will learn about saving Custom CMS block at the admin end. We already know how to create the same using the setup\/patch, you can check the same at <a href=\"https:\/\/webkul.com\/blog\/create-cms-block-installer-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/webkul.com\/blog\/create-cms-block-installer-magento-2\/<\/a>. In this way, we need to run Magento commands to register the same, to overcome the same we can do the same task by using the CMS model i.e. &#8220;Magento\\Cms\\Model\\BlockFactory&#8221;. <br>In this model, we can use the function save() to add the cms block programmatically.<\/p>\n\n\n\n<p>Let&#8217;s check the code on how to do the same:<\/p>\n\n\n\n<p>First, we will create a module in which we will create a controller to save the CMS block for that we require data to submit for that we will create a form by using the phtml file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\/**\n * Webkul Software.\n *\n * @category  Webkul\n * @package   Webkul_CmsBlockSave\n * @author    Webkul\n * @copyright Copyright (c)  Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\n?&gt;\n&lt;div&gt;\n    &lt;form method=&quot;post&quot; action=&quot;&lt;?= $block-&gt;escapeUrl($block-&gt;getUrl(&#039;cmsblocksave\/block\/save&#039;)); ?&gt;&quot; \n        enctype=&quot;multipart\/form-data&quot; data-mage-init=&#039;{&quot;validation&quot;:{}}&#039; id=&quot;wk-mpzcv-form&quot;&gt;\n        &lt;fieldset class=&quot;fieldset&quot;&gt;\n            &lt;?= $block-&gt;escapeHtml($block-&gt;getFormKeyBlockHtml()); ?&gt;\n            &lt;legend class=&quot;legend&quot;&gt;\n                &lt;span&gt;&lt;?= $block-&gt;escapeHtml(__(&quot;CMS Block&quot;)); ?&gt;&lt;\/span&gt;\n                &lt;button class=&quot;button wk-mp-btn&quot; type=&quot;submit&quot;&gt;\n                    &lt;span&gt;&lt;span&gt;&lt;?= $block-&gt;escapeHtml(__(&quot;Save CMS Block&quot;)); ?&gt;&lt;\/span&gt;&lt;\/span&gt;\n                &lt;\/button&gt;\n            &lt;\/legend&gt;\n            &lt;div class=&quot;field required&quot;&gt;\n                &lt;label for=&quot;mpzcv-region&quot; class=&quot;label&quot;&gt;\n                    &lt;span&gt;&lt;?= $block-&gt;escapeHtml(__(&quot;Title&quot;)); ?&gt;&lt;\/span&gt;\n                &lt;\/label&gt;\n                &lt;div class=&quot;control&quot;&gt;\n                    &lt;input type=&quot;text&quot; class=&quot;input-text required-entry validate-no-html-tags&quot; \n                        title=&quot;&lt;?= $block-&gt;escapeHtml(__(&#039;Title&#039;)); ?&gt;&quot; name=&quot;title&quot; \n                        id=&quot;mpzcv-region&quot; aria-required=&quot;true&quot;&gt;\n                &lt;\/div&gt;\n            &lt;\/div&gt;\n            &lt;div class=&quot;field required&quot;&gt;\n                &lt;label for=&quot;mpzcv-region&quot; class=&quot;label&quot;&gt;\n                    &lt;span&gt;&lt;?= $block-&gt;escapeHtml(__(&quot;identifier&quot;)); ?&gt;&lt;\/span&gt;\n                &lt;\/label&gt;\n                &lt;div class=&quot;control&quot;&gt;\n                    &lt;input type=&quot;text&quot; class=&quot;input-text required-entry validate-no-html-tags&quot; \n                        title=&quot;&lt;?= $block-&gt;escapeHtml(__(&#039;identifier&#039;)); ?&gt;&quot; name=&quot;identifier&quot; \n                        id=&quot;mpzcv-region&quot; aria-required=&quot;true&quot;&gt;\n                &lt;\/div&gt;\n            &lt;\/div&gt;\n            &lt;div class=&quot;field required&quot;&gt;\n                &lt;label for=&quot;mpzcv-zipcodes&quot; class=&quot;label&quot;&gt;\n                    &lt;span&gt;&lt;?= $block-&gt;escapeHtml(__(&quot;is_active&quot;)); ?&gt;&lt;\/span&gt;\n                &lt;\/label&gt;\n                &lt;div class=&quot;control&quot;&gt;\n                    &lt;select name=&quot;is_active&quot; class=&quot;required-entry&quot;&gt;\n                        &lt;option value=&quot;1&quot;&gt;\n                            &lt;?= $block-&gt;escapeHtml(__(&quot;Enable&quot;)); ?&gt;\n                        &lt;\/option&gt;\n                        &lt;option value=&quot;0&quot;&gt;\n                            &lt;?= $block-&gt;escapeHtml(__(&#039;Disable&#039;)); ?&gt;\n                        &lt;\/option&gt;\n                    &lt;\/select&gt;\n                &lt;\/div&gt;\n            &lt;\/div&gt;\n            &lt;div class=&quot;field required&quot;&gt;\n                &lt;label for=&quot;mpzcv-zipcodes&quot; class=&quot;label&quot;&gt;\n                    &lt;span&gt;&lt;?= $block-&gt;escapeHtml(__(&quot;is_active&quot;)); ?&gt;&lt;\/span&gt;\n                &lt;\/label&gt;\n                &lt;div class=&quot;control&quot;&gt;\n                    &lt;select multiple = &quot;multiple&quot; name=&quot;is_active&quot; class=&quot;required-entry&quot;&gt;\n                        &lt;option value=&quot;0&quot;&gt;All Store Views\n                            &lt;\/option&gt;\n                        &lt;option value=&quot;1&quot;&gt;Default Store View\n                        &lt;\/option&gt;\n                    &lt;\/select&gt;\n                &lt;\/div&gt;\n            &lt;\/div&gt;\n        &lt;\/fieldset&gt;\n    &lt;\/form&gt;\n&lt;\/div&gt;<\/pre>\n\n\n\n<p>Now we will create a controller to render the phtml file. like Controller\/Block\/Add.php<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\n\/**\n * Webkul Software.\n *\n * @category  Webkul\n * @package   Webkul_CmsBlockSave\n * @author    Webkul\n * @copyright Copyright (c)  Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\nnamespace Webkul\\CmsBlockSave\\Controller\\Block;\n\nuse Magento\\Framework\\App\\Action\\Action;\n\nuse Magento\\Framework\\App\\Action\\Context;\n\nuse Magento\\Framework\\View\\Result\\PageFactory;\n\nuse Magento\\Framework\\App\\RequestInterface;\n\nclass Add extends Action\n\n{\n\n\/**\n\n* @var \\Magento\\Customer\\Model\\Session\n\n*\/\n\nprotected $_customerSession;\n\n\/**\n\n* @var PageFactory\n\n*\/\n\nprotected $resultPageFactory;\n\n\/**\n\n* @var \\Magento\\Customer\\Model\\Url\n\n*\/\n\nprotected $url;\n\n\/**\n\n* @param Context $context\n\n* @param PageFactory $resultPageFactory\n\n* @param \\Magento\\Customer\\Model\\Session $customerSession\n\n* @param \\Magento\\Customer\\Model\\Url $url\n\n*\/\n\npublic function __construct(\n\nContext $context,\n\nPageFactory $resultPageFactory,\n\n\\Magento\\Customer\\Model\\Session $customerSession,\n\n\\Magento\\Customer\\Model\\Url $url,\n\n) {\n\n$this-&gt;_customerSession = $customerSession;\n\n$this-&gt;resultPageFactory = $resultPageFactory;\n\n$this-&gt;url = $url;\n\nparent::__construct($context);\n\n}\n\n\/**\n\n* Add Store Page\n\n*\n\n* @return \\Magento\\Framework\\View\\Result\\Page\n\n*\/\n\npublic function execute()\n\n{\n\n\/** @var \\Magento\\Framework\\View\\Result\\Page $resultPage *\/\n\n$resultPage = $this-&gt;resultPageFactory-&gt;create();\n\n$resultPage-&gt;getConfig()-&gt;getTitle()-&gt;set(__(&#039;Add Cms Block&#039;));\n\nreturn $resultPage;\n\n}\n\n}<\/pre>\n\n\n\n<p>to hit the controller we have to create a layout file: cmsblocksave_block_add.xml<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;!--\n\/**\n * Webkul Software.\n *\n * @category  Webkul\n * @package   Webkul_CmsBlockSave\n * @author    Webkul\n * @copyright Copyright (c)  Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\n--&gt;\n&lt;page xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd&quot;&gt;\n    &lt;body&gt;\n        &lt;referenceContainer name=&quot;content&quot;&gt;\n            &lt;block class=&quot;Webkul\\CmsBlockSave\\Block\\Cms\\Add&quot; name=&quot;cmsblocksave_block_add&quot; template=&quot;Webkul_CmsBlockSave::add.phtml&quot; cacheable=&quot;false&quot;\/&gt;\n        &lt;\/referenceContainer&gt;\n    &lt;\/body&gt;\n&lt;\/page&gt;<\/pre>\n\n\n\n<p>A form will be like mentioned below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"839\" height=\"625\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900.png\" alt=\"Selection_900\" class=\"wp-image-380915\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900.png 839w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900-300x223.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900-250x186.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900-768x572.png 768w\" sizes=\"(max-width: 839px) 100vw, 839px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>By this code, we will be able to show the form to save the custom CMS block at the admin end.<\/p>\n\n\n\n<p>Now we will check the code to save the cms block mentioned below<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\/**\n * Webkul Software.\n *\n * @category  Webkul\n * @package   Webkul_CmsBlockSave\n * @author    Webkul\n * @copyright Copyright (c)  Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\nnamespace Webkul\\CmsBlockSave\\Controller\\Block;\n\nuse Magento\\Framework\\App\\Action\\Action;\nuse Magento\\Framework\\App\\Action\\Context;\nuse Magento\\Framework\\View\\Result\\PageFactory;\nuse Magento\\Cms\\Model\\BlockFactory;\n\n\/**\n * Save CMS block action.\n *\/\nclass Save extends Action\n{\n    \/**\n     * @var DataPersistorInterface\n     *\/\n    protected $resultPageFactory;\n\n    \/**\n     * @var BlockFactory\n     *\/\n    private $blockFactory;\n\n    \/**\n     * @var BlockRepositoryInterface\n     *\/\n    private $coreRegistry;\n    private $jsonFactory;\n\n    \/**\n     * @param Context $context\n     * @param Registry $coreRegistry\n     * @param DataPersistorInterface $dataPersistor\n     * @param BlockFactory|null $blockFactory\n     * @param BlockRepositoryInterface|null $blockRepository\n     *\/\n    public function __construct(\n        Context $context,\n        PageFactory $resultPageFactory,\n        \\Magento\\Framework\\Registry $coreRegistry,\n        \\Magento\\Framework\\Controller\\Result\\JsonFactory $jsonFactory,\n        BlockFactory $blockFactory\n    ) {\n        $this-&gt;resultPageFactory = $resultPageFactory;\n        $this-&gt;coreRegistry = $coreRegistry;\n        $this-&gt;jsonFactory = $jsonFactory;\n        $this-&gt;blockFactory = $blockFactory;\n        parent::__construct($context);\n    }\n\n    \/**\n     * Save action\n     *\n     * @SuppressWarnings(PHPMD.CyclomaticComplexity)\n     * @return \\Magento\\Framework\\Controller\\ResultInterface\n     *\/\n    public function execute()\n    {\n        $testBlock = $this-&gt;getRequest()-&gt;getPostValue();\n        $this-&gt;blockFactory-&gt;create()-&gt;setData($testBlock)-&gt;save();\n        $returnData = &#091;&#039;status&#039; =&gt; true, &#039;data&#039; =&gt; $testBlock];\n        return $this-&gt;resultRedirectFactory-&gt;create()-&gt;setPath(\n            &#039;cmsblocksave\/block\/add&#039;,\n            &#091;&#039;_secure&#039; =&gt; $this-&gt;getRequest()-&gt;isSecure()]\n        );\n\n        return $this-&gt;jsonFactory-&gt;create()-&gt;setData($returnData);\n    }\n}<\/pre>\n\n\n\n<p>The output will be.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"623\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_901-1200x623.png\" alt=\"Selection_901\" class=\"wp-image-380913\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_901-1200x623.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_901-300x156.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_901-250x130.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_901-768x399.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_901.png 1271w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>That&#8217;s all for this blog \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we will learn about saving Custom CMS block at the admin end. We already know how to create the same using the setup\/patch, you can check the same at https:\/\/webkul.com\/blog\/create-cms-block-installer-magento-2\/. In this way, we need to run Magento commands to register the same, to overcome the same we can do the same <a href=\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":439,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9349,2070],"class_list":["post-380856","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-cms-block","tag-magento2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Saving custom CMS block from frontend in Magento 2 - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Saving custom CMS block from frontend in Magento 2 - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"In this blog, we will learn about saving Custom CMS block at the admin end. We already know how to create the same using the setup\/patch, you can check the same at https:\/\/webkul.com\/blog\/create-cms-block-installer-magento-2\/. In this way, we need to run Magento commands to register the same, to overcome the same we can do the same [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-10T09:17:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-15T06:07:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900.png\" \/>\n<meta name=\"author\" content=\"Ajay Singh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ajay Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/\"},\"author\":{\"name\":\"Ajay Singh\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/a34da891d20d341126f02e0f2716b63f\"},\"headline\":\"Saving custom CMS block from frontend in Magento 2\",\"datePublished\":\"2023-05-10T09:17:24+00:00\",\"dateModified\":\"2023-05-15T06:07:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/\"},\"wordCount\":223,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900.png\",\"keywords\":[\"cms block\",\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/\",\"url\":\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/\",\"name\":\"Saving custom CMS block from frontend in Magento 2 - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900.png\",\"datePublished\":\"2023-05-10T09:17:24+00:00\",\"dateModified\":\"2023-05-15T06:07:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900.png\",\"width\":839,\"height\":625,\"caption\":\"Selection_900\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Saving custom CMS block from frontend in Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/a34da891d20d341126f02e0f2716b63f\",\"name\":\"Ajay Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eb0e5d7a768feaf55e3b627fb8a98b0d994cf89381c4ca02db24fefe188aec5d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eb0e5d7a768feaf55e3b627fb8a98b0d994cf89381c4ca02db24fefe188aec5d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Ajay Singh\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/ajaysingh-tomar648\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Saving custom CMS block from frontend in Magento 2 - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"Saving custom CMS block from frontend in Magento 2 - Webkul Blog","og_description":"In this blog, we will learn about saving Custom CMS block at the admin end. We already know how to create the same using the setup\/patch, you can check the same at https:\/\/webkul.com\/blog\/create-cms-block-installer-magento-2\/. In this way, we need to run Magento commands to register the same, to overcome the same we can do the same [...]","og_url":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2023-05-10T09:17:24+00:00","article_modified_time":"2023-05-15T06:07:39+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900.png","type":"","width":"","height":""}],"author":"Ajay Singh","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Ajay Singh","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/"},"author":{"name":"Ajay Singh","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/a34da891d20d341126f02e0f2716b63f"},"headline":"Saving custom CMS block from frontend in Magento 2","datePublished":"2023-05-10T09:17:24+00:00","dateModified":"2023-05-15T06:07:39+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/"},"wordCount":223,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900.png","keywords":["cms block","Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/","url":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/","name":"Saving custom CMS block from frontend in Magento 2 - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900.png","datePublished":"2023-05-10T09:17:24+00:00","dateModified":"2023-05-15T06:07:39+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_900.png","width":839,"height":625,"caption":"Selection_900"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/save-a-custom-cms-block-from-frontend-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Saving custom CMS block from frontend in Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/a34da891d20d341126f02e0f2716b63f","name":"Ajay Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eb0e5d7a768feaf55e3b627fb8a98b0d994cf89381c4ca02db24fefe188aec5d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eb0e5d7a768feaf55e3b627fb8a98b0d994cf89381c4ca02db24fefe188aec5d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Ajay Singh"},"url":"https:\/\/webkul.com\/blog\/author\/ajaysingh-tomar648\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/380856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/439"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=380856"}],"version-history":[{"count":12,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/380856\/revisions"}],"predecessor-version":[{"id":381417,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/380856\/revisions\/381417"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=380856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=380856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=380856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}