{"id":342367,"date":"2022-07-05T05:24:53","date_gmt":"2022-07-05T05:24:53","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=342367"},"modified":"2025-12-16T13:43:44","modified_gmt":"2025-12-16T13:43:44","slug":"use-custom-variables-in-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/","title":{"rendered":"Custom Variables In Magento 2"},"content":{"rendered":"\n<p>Custom Variables in Magento 2 let you store reusable values that can be used throughout your store to display them anywhere across the frontend or backend. <\/p>\n\n\n\n<p>These can be simple strings, tokens, dynamic content, or formatted HTML.<\/p>\n\n\n\n<p>We can create custom variables to store any kind of HTML code or any plain data, like any third-party base URL, which we can use to call any third-party API within the Magento 2 store.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to create a custom variable in the admin panel<\/h3>\n\n\n\n<p>Go to Admin-&gt;System-&gt;Other Settings-&gt;Custom Variables<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"619\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page-1200x619.png\" alt=\"page\" class=\"wp-image-342625\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page-1200x619.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page-300x155.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page-250x129.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page-768x396.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page-1536x792.png 1536w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page.png 1920w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>Next, we need to add a custom variable and its value so that we can access it anywhere throughout our store.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"626\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/Custom-Variables-Other-Settings-System-Magento-Admin-1200x626.png\" alt=\"Custom-Variables-Other-Settings-System-Magento-Admin\" class=\"wp-image-342626\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/Custom-Variables-Other-Settings-System-Magento-Admin-1200x626.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/Custom-Variables-Other-Settings-System-Magento-Admin-300x156.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/Custom-Variables-Other-Settings-System-Magento-Admin-250x130.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/Custom-Variables-Other-Settings-System-Magento-Admin-768x401.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/Custom-Variables-Other-Settings-System-Magento-Admin-1536x801.png 1536w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/Custom-Variables-Other-Settings-System-Magento-Admin.png 1898w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>Now we will add our custom variable with plain value as well as html code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"619\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/1-1200x619.png\" alt=\"1\" class=\"wp-image-342627\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/1-1200x619.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/1-300x155.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/1-250x129.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/1-768x396.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/1-1536x792.png 1536w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/1.png 1920w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"626\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/2-1200x626.png\" alt=\"2\" class=\"wp-image-342628\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/2-1200x626.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/2-300x156.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/2-250x130.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/2-768x401.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/2-1536x801.png 1536w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/2.png 1898w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>We have added our custom variable to the Magento 2 admin.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Now we are going to access that variable in the frontend block.<\/h3>\n\n\n\n<p>We can do it with the code below<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\Demo\\Block;\nclass Header extends \\Magento\\Framework\\View\\Element\\Template\n{\n    \/**\n     * @var \\Magento\\Variable\\Model\\Variable\n     *\/\t\n    protected $customvariable;\n\n    \/**\n     * Constructor\n     *\n     * @param \\Magento\\Framework\\View\\Element\\Template\\Context $context\n     * @param \\Magento\\Variable\\Model\\Variable $customvariable\n     *\/\n    public function __construct(\n        \\Magento\\Framework\\View\\Element\\Template\\Context $context,\n        \\Magento\\Variable\\Model\\Variable $customvariable\n     ) {\n\t    $this-&gt;customvariable = $customvariable;\n\t    parent::__construct($context);\n     }\n\n    \/**\n     * Return plain value of the variable\n     *\n     * @return string\n     *\/\n     public function getPlainValue()\n     { \n        $model = $this-&gt;customvariable-&gt;loadByCode(&#039;webkul_token&#039;);\n\t    $plain_value = $model-&gt;getPlainValue();\n        return $plain_value;\n     }\n\n     \/**\n      * Return html value of the variable\n      *\n      * @return string\n      *\/\n      public function getHtmlValue()\n      {\n\t    $model = $this-&gt;customvariable-&gt;loadByCode(&#039;webkul_token&#039;);\n\t    $html_value = $model-&gt;getHtmlValue();\n\t    return $html_value;\n      }\n}<\/pre>\n\n\n\n<p>We can call the above functions anywhere in the phtml file from the above block, which we have created.<\/p>\n\n\n\n<p>The output will be like below on the homepage, with the  code below<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;div&gt;\n    &lt;?php echo $block-&gt;getPlainValue();?&gt;\n&lt;\/div&gt;\n&lt;div&gt;\n    &lt;?php echo $block-&gt;getHtmlValue();?&gt;\n&lt;\/div&gt;<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"619\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/3-1200x619.png\" alt=\"3\" class=\"wp-image-342629\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/3-1200x619.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/3-300x155.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/3-250x129.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/3-768x396.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/3-1536x792.png 1536w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/3.png 1920w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>You can read more about custom variables in Magento 2 docs:-&gt;<\/p>\n\n\n\n<p><a href=\"https:\/\/experienceleague.adobe.com\/en\/docs\/commerce-admin\/systems\/variables\/variables-custom\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/docs.magento.com\/user-guide\/marketing\/variables-custom.html<\/a><\/p>\n\n\n\n<p>Check for other blogs as well: <a href=\"https:\/\/webkul.com\/blog\/magento-2-layout-and-templates\/\">https:\/\/webkul.com\/blog\/magento-2-layout-and-templates\/<\/a><\/p>\n\n\n\n<p>For any technical support inquiries, please email us at <a href=\"mailto:support@webkul.com\">support@webkul.com<\/a><\/p>\n\n\n\n<p>Browse our high-quality <a href=\"https:\/\/store.webkul.com\/Magento-2.html\">Magento 2 extensions<\/a> created by certified Adobe Commerce developers.<\/p>\n\n\n\n<p>For expert consultation or custom feature development, <a href=\"https:\/\/webkul.com\/hire-magento-developers\/\">hire experienced Magento 2 developers<\/a> for your project.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Custom Variables in Magento 2 let you store reusable values that can be used throughout your store to display them anywhere across the frontend or backend. These can be simple strings, tokens, dynamic content, or formatted HTML. We can create custom variables to store any kind of HTML code or any plain data, like any <a href=\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":605,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,1],"tags":[],"class_list":["post-342367","post","type-post","status-publish","format-standard","hentry","category-magento2","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Custom Variables In Magento 2 - %<\/title>\n<meta name=\"description\" content=\"This guide explains how to create custom variables in Magento 2, load them in blocks, and display their plain or HTML values in .phtml files.\" \/>\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\/use-custom-variables-in-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Custom Variables In Magento 2 - %\" \/>\n<meta property=\"og:description\" content=\"This guide explains how to create custom variables in Magento 2, load them in blocks, and display their plain or HTML values in .phtml files.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/\" \/>\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=\"2022-07-05T05:24:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-16T13:43:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page-1200x619.png\" \/>\n<meta name=\"author\" content=\"Atif Yaqoob\" \/>\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=\"Atif Yaqoob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/\"},\"author\":{\"name\":\"Atif Yaqoob\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/2273bf3f70f0107d46749e115bf818fa\"},\"headline\":\"Custom Variables In Magento 2\",\"datePublished\":\"2022-07-05T05:24:53+00:00\",\"dateModified\":\"2025-12-16T13:43:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/\"},\"wordCount\":262,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page-1200x619.png\",\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/\",\"name\":\"Custom Variables In Magento 2 - %\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page-1200x619.png\",\"datePublished\":\"2022-07-05T05:24:53+00:00\",\"dateModified\":\"2025-12-16T13:43:44+00:00\",\"description\":\"This guide explains how to create custom variables in Magento 2, load them in blocks, and display their plain or HTML values in .phtml files.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page.png\",\"width\":1920,\"height\":990,\"caption\":\"page\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Custom Variables 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\/2273bf3f70f0107d46749e115bf818fa\",\"name\":\"Atif Yaqoob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5ed5b0a496b935107cbfc11af454d90dc3e6458b661598c2027cfcfbbf88a915?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\/5ed5b0a496b935107cbfc11af454d90dc3e6458b661598c2027cfcfbbf88a915?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Atif Yaqoob\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/atif-yakoob869\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Custom Variables In Magento 2 - %","description":"This guide explains how to create custom variables in Magento 2, load them in blocks, and display their plain or HTML values in .phtml files.","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\/use-custom-variables-in-magento2\/","og_locale":"en_US","og_type":"article","og_title":"Custom Variables In Magento 2 - %","og_description":"This guide explains how to create custom variables in Magento 2, load them in blocks, and display their plain or HTML values in .phtml files.","og_url":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2022-07-05T05:24:53+00:00","article_modified_time":"2025-12-16T13:43:44+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page-1200x619.png","type":"","width":"","height":""}],"author":"Atif Yaqoob","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Atif Yaqoob","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/"},"author":{"name":"Atif Yaqoob","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/2273bf3f70f0107d46749e115bf818fa"},"headline":"Custom Variables In Magento 2","datePublished":"2022-07-05T05:24:53+00:00","dateModified":"2025-12-16T13:43:44+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/"},"wordCount":262,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page-1200x619.png","articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/","url":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/","name":"Custom Variables In Magento 2 - %","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page-1200x619.png","datePublished":"2022-07-05T05:24:53+00:00","dateModified":"2025-12-16T13:43:44+00:00","description":"This guide explains how to create custom variables in Magento 2, load them in blocks, and display their plain or HTML values in .phtml files.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/07\/page.png","width":1920,"height":990,"caption":"page"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/use-custom-variables-in-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Custom Variables 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\/2273bf3f70f0107d46749e115bf818fa","name":"Atif Yaqoob","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5ed5b0a496b935107cbfc11af454d90dc3e6458b661598c2027cfcfbbf88a915?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\/5ed5b0a496b935107cbfc11af454d90dc3e6458b661598c2027cfcfbbf88a915?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Atif Yaqoob"},"url":"https:\/\/webkul.com\/blog\/author\/atif-yakoob869\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/342367","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\/605"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=342367"}],"version-history":[{"count":8,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/342367\/revisions"}],"predecessor-version":[{"id":517567,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/342367\/revisions\/517567"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=342367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=342367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=342367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}