{"id":188405,"date":"2019-07-24T10:11:08","date_gmt":"2019-07-24T10:11:08","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=188405"},"modified":"2019-07-24T10:12:04","modified_gmt":"2019-07-24T10:12:04","slug":"get-the-static-block-content-in-controller","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/","title":{"rendered":"Get the Static Block Content in Controller"},"content":{"rendered":"\n<p>Today we will learn how we can get the cms\/static block content in Controller&#8217;s action file.<br>Here we go.<br><br>To get the job done, we need to use the following classes :<br><\/p>\n\n\n\n<p>\\Magento\\Cms\\Model\\Block<br>\\Magento\\Cms\\Model\\Template\\<em>FilterProvider<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n$block = $objectManager-&gt;create(\\Magento\\Cms\\Model\\Block::class);\n$storeId = 1;\/\/it can be any active store id.\n$blockId = 12;\/\/ it can be any available block id.\n$block-&gt;setStoreId($storeId)-&gt;load($blockId);\n$html = $objectManager-&gt;create(\\Magento\\Cms\\Model\\Template\\FilterProvider::class)-&gt;getBlockFilter()-&gt;setStoreId($storeId)-&gt;filter($block-&gt;getContent());\n<\/pre>\n\n\n\n<p>This is a simple code that helps us to get the html content of the static\/cms block  to use it further.<br>happy coding :).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we will learn how we can get the cms\/static block content in Controller&#8217;s action file.Here we go. To get the job done, we need to use the following classes : \\Magento\\Cms\\Model\\Block\\Magento\\Cms\\Model\\Template\\FilterProvider $objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance(); $block = $objectManager-&gt;create(\\Magento\\Cms\\Model\\Block::class); $storeId = 1;\/\/it can be any active store id. $blockId = 12;\/\/ it can be any available <a href=\"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":170,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[6783,1195,2056,2070,9348],"class_list":["post-188405","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-block","tag-cms-2","tag-magento","tag-magento2","tag-static-block"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Get the Static Block Content in Controller - 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\/get-the-static-block-content-in-controller\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get the Static Block Content in Controller - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Today we will learn how we can get the cms\/static block content in Controller&#8217;s action file.Here we go. To get the job done, we need to use the following classes : MagentoCmsModelBlockMagentoCmsModelTemplateFilterProvider $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $block = $objectManager-&gt;create(MagentoCmsModelBlock::class); $storeId = 1;\/\/it can be any active store id. $blockId = 12;\/\/ it can be any available [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/\" \/>\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=\"2019-07-24T10:11:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-07-24T10:12:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prabhat Rawat\" \/>\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=\"Prabhat Rawat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/\"},\"author\":{\"name\":\"Prabhat Rawat\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/3d52d6c1ad8a809d2f7548e6a9c3358f\"},\"headline\":\"Get the Static Block Content in Controller\",\"datePublished\":\"2019-07-24T10:11:08+00:00\",\"dateModified\":\"2019-07-24T10:12:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/\"},\"wordCount\":72,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"block\",\"cms\",\"magento\",\"Magento2\",\"static block\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/\",\"url\":\"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/\",\"name\":\"Get the Static Block Content in Controller - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2019-07-24T10:11:08+00:00\",\"dateModified\":\"2019-07-24T10:12:04+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get the Static Block Content in Controller\"}]},{\"@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\/3d52d6c1ad8a809d2f7548e6a9c3358f\",\"name\":\"Prabhat Rawat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/616ec5deaf63b72b3003cf99e608ae354f4d373cee8d25b2d0bfa65cab270ad8?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\/616ec5deaf63b72b3003cf99e608ae354f4d373cee8d25b2d0bfa65cab270ad8?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Prabhat Rawat\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/prabhat-rawat763\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get the Static Block Content in Controller - 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\/get-the-static-block-content-in-controller\/","og_locale":"en_US","og_type":"article","og_title":"Get the Static Block Content in Controller - Webkul Blog","og_description":"Today we will learn how we can get the cms\/static block content in Controller&#8217;s action file.Here we go. To get the job done, we need to use the following classes : MagentoCmsModelBlockMagentoCmsModelTemplateFilterProvider $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $block = $objectManager-&gt;create(MagentoCmsModelBlock::class); $storeId = 1;\/\/it can be any active store id. $blockId = 12;\/\/ it can be any available [...]","og_url":"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2019-07-24T10:11:08+00:00","article_modified_time":"2019-07-24T10:12:04+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Prabhat Rawat","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Prabhat Rawat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/"},"author":{"name":"Prabhat Rawat","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/3d52d6c1ad8a809d2f7548e6a9c3358f"},"headline":"Get the Static Block Content in Controller","datePublished":"2019-07-24T10:11:08+00:00","dateModified":"2019-07-24T10:12:04+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/"},"wordCount":72,"commentCount":2,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["block","cms","magento","Magento2","static block"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/","url":"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/","name":"Get the Static Block Content in Controller - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2019-07-24T10:11:08+00:00","dateModified":"2019-07-24T10:12:04+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/get-the-static-block-content-in-controller\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Get the Static Block Content in Controller"}]},{"@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\/3d52d6c1ad8a809d2f7548e6a9c3358f","name":"Prabhat Rawat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/616ec5deaf63b72b3003cf99e608ae354f4d373cee8d25b2d0bfa65cab270ad8?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\/616ec5deaf63b72b3003cf99e608ae354f4d373cee8d25b2d0bfa65cab270ad8?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Prabhat Rawat"},"url":"https:\/\/webkul.com\/blog\/author\/prabhat-rawat763\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/188405","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\/170"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=188405"}],"version-history":[{"count":4,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/188405\/revisions"}],"predecessor-version":[{"id":188416,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/188405\/revisions\/188416"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=188405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=188405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=188405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}