{"id":1049,"date":"2016-01-27T12:04:01","date_gmt":"2016-01-27T12:04:01","guid":{"rendered":"http:\/\/invisiblezero.net\/?p=1049"},"modified":"2024-03-18T15:56:05","modified_gmt":"2024-03-18T15:56:05","slug":"magento-adding-custom-variables-to-magento-static-blocks","status":"publish","type":"post","link":"http:\/\/ndthanh.com\/magento-adding-custom-variables-to-magento-static-blocks\/","title":{"rendered":"Magento – Adding custom variables to Magento Static Blocks"},"content":{"rendered":"\n

I\u2019ve been asked to customize the front page of a magento store. The client wanted the ability to specify a set of variables that can be used in CMS static blocks so static blocks can be a little more dynamic.<\/p>\n\n\n\n

By default, the standard magento CMS static blocks don\u2019t provide access to the custom variables. so I thought I was going to have to build an extension to pass the variables in. However after a little bit of finding, I found that this functionality is available as standard in Magento, you just need to do it properly.<\/p>\n\n\n\n\n\n\n\n

The way to do this is as follows. Within you template file add in the following code:<\/p>\n\n\n\n

\n$quote = $this->getData(<\/code>'quote');\n$identifier = Mage::getStoreConfig('qquoteadv\/patches\/quote_success_msg<\/code>');\n\n$filter = Mage::getModel('core\/email_template_filter');\n$filter->setVariables(array('quote_number' => $quote-<\/code>>increment_id));\n$block = $this->getLayout()->createBlock(<\/code>'cms\/block')->setBlockId($identifier);\n\n$html = $filter->filter($block->toHtml());<\/code><\/pre>\n\n\n\n

This will then display the static block with your variables expanded to values you\u2019ve set.<\/p>\n\n\n\n

then you can use this variable in cms block {{var quote_number}}<\/p>\n","protected":false},"excerpt":{"rendered":"

I\u2019ve been asked to customize the front page of a magento store. The client wanted the ability to specify a set of variables that can be used in CMS static blocks so static blocks can be a little more dynamic. By default, the standard magento CMS static blocks don\u2019t provide access to the custom variables….<\/p>\n

Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":1275,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44],"tags":[59,62,51],"aioseo_notices":[],"views":21,"_links":{"self":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/1049"}],"collection":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/comments?post=1049"}],"version-history":[{"count":9,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/1049\/revisions"}],"predecessor-version":[{"id":1343,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/1049\/revisions\/1343"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/media\/1275"}],"wp:attachment":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/media?parent=1049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/categories?post=1049"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/tags?post=1049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}