{"id":68407,"date":"2016-12-17T12:54:48","date_gmt":"2016-12-17T12:54:48","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=68407"},"modified":"2025-12-18T09:26:00","modified_gmt":"2025-12-18T09:26:00","slug":"intialize-js-component-using-lauyout-xml-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/","title":{"rendered":"How to Intialize Js Component Using Layout XML in Magento2"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">How to use Initialize Js Component on custom phtml file using layout xml in Magento2<\/h3>\n\n\n\n<p>In Magento2 mainly we have seen on checkout page all Js components loads using xml, these components are defined in <strong>checkout_index_index.xml<\/strong> file.<\/p>\n\n\n\n<p>We can also define our custom Js Components using our xml Layout File.<\/p>\n\n\n\n<p>1. Let&#8217;s create our required xml file: <strong>Webkul\/CustomJs\/view\/frontend\/layout\/customjs_index_index.xml<\/strong><\/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_CustomJs\n * @author    Webkul\n * @copyright Copyright (c) 2010-2016 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;update handle=&quot;customer_account&quot;\/&gt;\n    &lt;body&gt;\n        &lt;referenceContainer name=&quot;content&quot;&gt;\n            &lt;block class=&quot;Webkul\\CustomJs\\Block\\CustomJs&quot; name=&quot;customjs_test&quot; template=&quot;Webkul_CustomJs::account\/customjs.phtml&quot; cacheable=&quot;false&quot;&gt;\n            &lt;\/block&gt;\n        &lt;\/referenceContainer&gt;\n    &lt;\/body&gt;\n&lt;\/page&gt;<\/pre>\n\n\n\n<p>2. Let&#8217;s create our required Controller file: <strong>Webkul\/CustomJs\/Controller\/Index\/Index.php<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\CustomJs\\Controller\\Index;\n\nuse Magento\\Framework\\App\\Action\\Action;\nuse Magento\\Framework\\App\\Action\\Context;\nuse Magento\\Framework\\View\\Result\\PageFactory;\n\n\/**\n * Webkul Marketplace Landing page Index Controller.\n *\/\nclass Index extends Action\n{\n    \/**\n     * @var PageFactory\n     *\/\n    protected $resultPageFactory;\n\n    \/**\n     * Constructor\n     *\n     * @param Context $context\n     * @param PageFactory $resultPageFactory\n     *\/\n    public function __construct(\n        Context $context,\n        PageFactory $resultPageFactory\n    ) {\n        $this-&gt;resultPageFactory = $resultPageFactory;\n        parent::__construct($context);\n    }\n\n    \/**\n     * Execute Action\n     *\n     * @return void\n     *\/\n    public function execute()\n    {\n        $resultPage = $this-&gt;resultPageFactory-&gt;create();\n        $resultPage-&gt;getConfig()-&gt;getTitle()-&gt;set(__(&#039;Custom JS&#039;));\n\n        return $resultPage;\n    }\n}<\/pre>\n\n\n\n<p>3. Create Block file <strong>Webkul\/CustomJs\/Block\/CustomJs.php<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\/**\n * Webkul Software.\n *\n * @category  Webkul\n * @package   Webkul_CustomJs\n * @author    Webkul\n * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\nnamespace Webkul\\CustomJs\\Block;\n\nclass CustomJs extends \\Magento\\Framework\\View\\Element\\Template\n{\n    \/**\n     * @var array\n     *\/\n    protected $jsLayout;\n\n    \/**\n     * @param \\Magento\\Framework\\View\\Element\\Template\\Context $context\n     * @param array $data\n     *\/\n    public function __construct(\n        \\Magento\\Framework\\View\\Element\\Template\\Context $context,\n        array $data = &#091;]\n    ) {\n        parent::__construct($context, $data);\n        $this-&gt;jsLayout = isset($data&#091;&#039;jsLayout&#039;]) &amp;&amp; is_array($data&#091;&#039;jsLayout&#039;]) ? $data&#091;&#039;jsLayout&#039;] : &#091;];\n    }\n\n    \/**\n     * @return string\n     *\/\n    public function getJsLayout()\n    {\n        return \\Zend_Json::encode($this-&gt;jsLayout);\n    }\n}<\/pre>\n\n\n\n<p>4. Now we need to create our phtml file<strong> Webkul\/CustomJs\/view\/frontend\/templates\/account\/customjs.phtml<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;div id=&quot;customjs-component&quot; data-bind=&quot;scope:&#039;custom-js-field&#039;&quot;&gt;\n    &lt;!-- ko template: getTemplate() --&gt;&lt;!-- \/ko --&gt;\n    &lt;script type=&quot;text\/x-magento-init&quot;&gt;\n    {\n        &quot;#customjs-component&quot;: {\n            &quot;Magento_Ui\/js\/core\/app&quot;:  &lt;?php \/* @escapeNotVerified *\/ echo $block-&gt;getJsLayout();?&gt;\n        }\n    }\n    &lt;\/script&gt;\n&lt;\/div&gt;<\/pre>\n\n\n\n<p>Ok, now takes a closer look on above code.<br>we have initialized our custom compenent and load the js components by getJsLayout() Method.<\/p>\n\n\n\n<p>You can see we have defined this Method in our Block File, which is providing Js layouts.<br>But we haven&#8217;t defined jsLayout in our&nbsp;<strong>customjs_index_index.xml<\/strong> file yet.<\/p>\n\n\n\n<p>Let&#8217;s open it again and update with this code.<\/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_CustomJs\n * @author    Webkul\n * @copyright Copyright (c) 2010-2016 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;update handle=&quot;customer_account&quot;\/&gt;\n    &lt;body&gt;\n        &lt;referenceContainer name=&quot;content&quot;&gt;\n            &lt;block class=&quot;Webkul\\CustomJs\\Block\\CustomJs&quot; name=&quot;customjs_test&quot; template=&quot;Webkul_CustomJs::account\/customjs.phtml&quot; cacheable=&quot;false&quot;&gt;\n                &lt;arguments&gt;\n                    &lt;argument name=&quot;jsLayout&quot; xsi:type=&quot;array&quot;&gt;\n                        &lt;item name=&quot;components&quot; xsi:type=&quot;array&quot;&gt;\n                            &lt;item name=&quot;custom-js-field&quot; xsi:type=&quot;array&quot;&gt;\n                                &lt;item name=&quot;component&quot; xsi:type=&quot;string&quot;&gt;uiComponent&lt;\/item&gt;\n                                &lt;item name=&quot;config&quot; xsi:type=&quot;array&quot;&gt;\n                                    &lt;item name=&quot;template&quot; xsi:type=&quot;string&quot;&gt;Webkul_CustomJs\/js-group&lt;\/item&gt;\n                                &lt;\/item&gt;\n                                &lt;item name=&quot;children&quot; xsi:type=&quot;array&quot;&gt;\n                                    &lt;item name=&quot;my-child-js&quot; xsi:type=&quot;array&quot;&gt;\n                                        &lt;item name=&quot;sortOrder&quot; xsi:type=&quot;string&quot;&gt;1&lt;\/item&gt;\n                                        &lt;item name=&quot;component&quot; xsi:type=&quot;string&quot;&gt;Webkul_CustomJs\/js\/view\/my-child-js&lt;\/item&gt;\n                                        &lt;item name=&quot;displayArea&quot; xsi:type=&quot;string&quot;&gt;my-child-js&lt;\/item&gt;\n                                    &lt;\/item&gt;\n                                &lt;\/item&gt;\n                            &lt;\/item&gt;\n                        &lt;\/item&gt;\n                    &lt;\/argument&gt;\n                &lt;\/arguments&gt;\n            &lt;\/block&gt;\n        &lt;\/referenceContainer&gt;\n    &lt;\/body&gt;\n&lt;\/page&gt;<\/pre>\n\n\n\n<p>Now what we really did here,<br>We have defined the jsLayout as arguments, so we can get all these arguments in our Block File as<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">$this-&gt;jsLayout = isset($data&#091;&#039;jsLayout&#039;]) &amp;&amp; is_array($data&#091;&#039;jsLayout&#039;]) ? $data&#091;&#039;jsLayout&#039;] : &#091;];<\/pre>\n\n\n\n<p>You will see that all the components with its children nodes are assigned to <strong>&#8220;Magento_Ui\/js\/core\/app.js&#8221;<\/strong> component.<\/p>\n\n\n\n<p>We have called a function getTemplate() in our phtml file <strong><!-- ko template: getTemplate() --><!-- \/ko --><\/strong><\/p>\n\n\n\n<p>When this method is called Magento checks for the template defined in <strong>custom-js-field<\/strong> scope which we have defined as attribute in our phtml file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;div id=&quot;customjs-component&quot; data-bind=&quot;scope:&#039;custom-js-field&#039;&quot;&gt;<\/pre>\n\n\n\n<p>We have also defined <strong>children<\/strong> components in our&nbsp;<strong>customjs_index_index.xml<\/strong> file, let learn how we can use them as well.<\/p>\n\n\n\n<p>Let create Html template file <strong>Webkul\/CustomJs\/view\/frontend\/web\/template\/js-group.html<\/strong> which we have defined.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;item name=&quot;components&quot; xsi:type=&quot;array&quot;&gt;\n    &lt;item name=&quot;custom-js-field&quot; xsi:type=&quot;array&quot;&gt;\n        &lt;item name=&quot;component&quot; xsi:type=&quot;string&quot;&gt;uiComponent&lt;\/item&gt;\n        &lt;item name=&quot;config&quot; xsi:type=&quot;array&quot;&gt;\n            &lt;item name=&quot;template&quot; xsi:type=&quot;string&quot;&gt;Webkul_CustomJs\/js-group&lt;\/item&gt;\n        &lt;\/item&gt;<\/pre>\n\n\n\n<p>Open this file and update with this code.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;!-- \n    \/**\n * Webkul Software.\n *\n * @category  Webkul\n * @package   Webkul_CustomJs\n * @author    Webkul\n * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\n --&gt;\n \n&lt;!-- ko foreach: getRegion(&#039;my-child-js&#039;) --&gt;\n&lt;!-- ko template: getTemplate() --&gt;&lt;!-- \/ko --&gt;\n&lt;!--\/ko--&gt;<\/pre>\n\n\n\n<p>When this template load it will look for the area with name <strong>my-child-js<\/strong> in&nbsp;<strong>customjs_index_index.xml<\/strong> file.<\/p>\n\n\n\n<p>we already defined it in our xml file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;item name=&quot;children&quot; xsi:type=&quot;array&quot;&gt;\n    &lt;item name=&quot;my-child-js&quot; xsi:type=&quot;array&quot;&gt;\n        &lt;item name=&quot;sortOrder&quot; xsi:type=&quot;string&quot;&gt;1&lt;\/item&gt;\n        &lt;item name=&quot;component&quot; xsi:type=&quot;string&quot;&gt;Webkul_CustomJs\/js\/view\/my-child-js&lt;\/item&gt;\n        &lt;item name=&quot;displayArea&quot; xsi:type=&quot;string&quot;&gt;my-child-js&lt;\/item&gt;\n    &lt;\/item&gt;\n&lt;\/item&gt;<\/pre>\n\n\n\n<p>Children items can also contains define component, we can define nested children as many as we want.<\/p>\n\n\n\n<p>Now, we need to create <strong>Webkul\/CustomJs\/view\/frontend\/web\/js\/view\/my-child-js.js<\/strong> file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\/**\n * Webkul Software.\n *\n * @category  Webkul\n * @package   Webkul_CustomJs\n * @author    Webkul\n * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\n\/*jshint browser:true jquery:true*\/\n\/*global alert*\/\n\ndefine(&#091;&#039;jquery&#039;, &#039;uiComponent&#039;, &#039;ko&#039;], function ($, Component, ko) {\n    &#039;use strict&#039;;\n    return Component.extend({\n        defaults: {\n            template: &#039;Webkul_CustomJs\/view\/my-child-js&#039;\n        },\n        initialize: function () {\n            this.customerName = ko.observableArray(&#091;]);\n            this.customerData = ko.observable(&#039;&#039;);\n            this._super();\n        },\n\n        addNewCustomer: function () {\n            this.customerName.push({name:this.customerData()});\n            this.customerData(&#039;&#039;);\n        }\n    });\n});<\/pre>\n\n\n\n<p>In this case, we call html template from our js component by passing template key with value on defaults object.<br>Also, we can call same html template file from xml for example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;item name=&quot;config&quot; xsi:type=&quot;array&quot;&gt;\n    &lt;item name=&quot;template&quot; xsi:type=&quot;string&quot;&gt;Webkul_CustomJs\/js-group&lt;\/item&gt;\n &lt;\/item&gt;<\/pre>\n\n\n\n<p>Now, we need to create html template <strong>Webkul\/CustomJs\/view\/frontend\/web\/template\/view\/my-child-js.html<\/strong> file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;div class=&quot;component-wrapper&quot;&gt;\n    &lt;div class=&quot;field&quot;&gt;\n        &lt;label class=&quot;label&quot; for=&quot;email&quot;&gt;&lt;span data-bind=&quot;i18n: &#039;New Record&#039;&quot;&gt;&lt;\/span&gt;&lt;\/label&gt;\n        &lt;div class=&quot;control&quot;&gt;\n            &lt;input name=&quot;customername&quot;\n                   id=&quot;customername&quot;\n                   type=&quot;text&quot;\n                   class=&quot;input-text&quot;\n                   data-bind=&quot;value: customerData&quot;&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n    &lt;div class=&quot;primary&quot;&gt;\n        &lt;button type=&quot;button&quot; class=&quot;action action-login secondary&quot; data-bind=&quot;click: addNewCustomer&quot;&gt;\n            &lt;span data-bind=&quot;i18n: &#039;Save&#039;&quot;&gt;&lt;\/span&gt;\n        &lt;\/button&gt;\n    &lt;\/div&gt;\n\n    &lt;div class=&quot;customer-list&quot; style=&quot;width: 20%;background: gray;margin-top: 10px;&quot; data-bind=&quot;foreach: customerName&quot;&gt;\n        &lt;li data-bind=&quot;text: name&quot;&gt;&lt;\/li&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;<\/pre>\n\n\n\n<p>That&#8217;s It!<\/p>\n\n\n\n<p>If you require technical support, feel free to email us at&nbsp;<a href=\"mailto:support@webkul.com\">support@webkul.com<\/a>.<\/p>\n\n\n\n<p>Additionally, explore a wide array of solutions to boost your store\u2019s capabilities by visiting the&nbsp;<a href=\"https:\/\/store.webkul.com\/Magento-2.html\">Adobe Commerce modules&nbsp;<\/a>section.<\/p>\n\n\n\n<p>For expert advice or to create tailored features,&nbsp;<a href=\"https:\/\/webkul.com\/hire-magento-developers\/\">hire Adobe Commerce Developers<\/a>&nbsp;for your project.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to use Initialize Js Component on custom phtml file using layout xml in Magento2 In Magento2 mainly we have seen on checkout page all Js components loads using xml, these components are defined in checkout_index_index.xml file. We can also define our custom Js Components using our xml Layout File. 1. Let&#8217;s create our required <a href=\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":69,"featured_media":66844,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,3286],"tags":[4197,2070,4198],"class_list":["post-68407","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","category-magento2-1","tag-magento-js-component","tag-magento2","tag-magento2-uicomponent"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Intialize Js Component Using Layout XML in Magento2<\/title>\n<meta name=\"description\" content=\"How to use Initialize Js Component on custom phtml file using layout xml in Magento2. Mainly we have seen on checkout page all Js components load using xm\" \/>\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\/intialize-js-component-using-lauyout-xml-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Intialize Js Component Using Layout XML in Magento2\" \/>\n<meta property=\"og:description\" content=\"How to use Initialize Js Component on custom phtml file using layout xml in Magento2. Mainly we have seen on checkout page all Js components load using xm\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-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=\"2016-12-17T12:54:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-18T09:26:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Magneto-Code-Snippet.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Mahesh 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=\"Mahesh Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/\"},\"author\":{\"name\":\"Mahesh Singh\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/53d3b977a0ab5adcf32aef9f97e595bd\"},\"headline\":\"How to Intialize Js Component Using Layout XML in Magento2\",\"datePublished\":\"2016-12-17T12:54:48+00:00\",\"dateModified\":\"2025-12-18T09:26:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/\"},\"wordCount\":470,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Magneto-Code-Snippet.png\",\"keywords\":[\"Magento Js Component\",\"Magento2\",\"Magento2 uiComponent\"],\"articleSection\":[\"Magento2\",\"Magento2.1\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/\",\"name\":\"How to Intialize Js Component Using Layout XML in Magento2\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Magneto-Code-Snippet.png\",\"datePublished\":\"2016-12-17T12:54:48+00:00\",\"dateModified\":\"2025-12-18T09:26:00+00:00\",\"description\":\"How to use Initialize Js Component on custom phtml file using layout xml in Magento2. Mainly we have seen on checkout page all Js components load using xm\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Magneto-Code-Snippet.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Magneto-Code-Snippet.png\",\"width\":825,\"height\":260},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Intialize Js Component Using Layout XML in Magento2\"}]},{\"@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\/53d3b977a0ab5adcf32aef9f97e595bd\",\"name\":\"Mahesh Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f4c013ebf7008223382b8a49203e6d354677e8baff0eca373e6e4266efa762da?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\/f4c013ebf7008223382b8a49203e6d354677e8baff0eca373e6e4266efa762da?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Mahesh Singh\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/mahesh721\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Intialize Js Component Using Layout XML in Magento2","description":"How to use Initialize Js Component on custom phtml file using layout xml in Magento2. Mainly we have seen on checkout page all Js components load using xm","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\/intialize-js-component-using-lauyout-xml-magento2\/","og_locale":"en_US","og_type":"article","og_title":"How to Intialize Js Component Using Layout XML in Magento2","og_description":"How to use Initialize Js Component on custom phtml file using layout xml in Magento2. Mainly we have seen on checkout page all Js components load using xm","og_url":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-12-17T12:54:48+00:00","article_modified_time":"2025-12-18T09:26:00+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Magneto-Code-Snippet.png","type":"image\/png"}],"author":"Mahesh Singh","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Mahesh Singh","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/"},"author":{"name":"Mahesh Singh","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/53d3b977a0ab5adcf32aef9f97e595bd"},"headline":"How to Intialize Js Component Using Layout XML in Magento2","datePublished":"2016-12-17T12:54:48+00:00","dateModified":"2025-12-18T09:26:00+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/"},"wordCount":470,"commentCount":1,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Magneto-Code-Snippet.png","keywords":["Magento Js Component","Magento2","Magento2 uiComponent"],"articleSection":["Magento2","Magento2.1"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/","url":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/","name":"How to Intialize Js Component Using Layout XML in Magento2","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Magneto-Code-Snippet.png","datePublished":"2016-12-17T12:54:48+00:00","dateModified":"2025-12-18T09:26:00+00:00","description":"How to use Initialize Js Component on custom phtml file using layout xml in Magento2. Mainly we have seen on checkout page all Js components load using xm","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Magneto-Code-Snippet.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Magneto-Code-Snippet.png","width":825,"height":260},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/intialize-js-component-using-lauyout-xml-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Intialize Js Component Using Layout XML in Magento2"}]},{"@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\/53d3b977a0ab5adcf32aef9f97e595bd","name":"Mahesh Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f4c013ebf7008223382b8a49203e6d354677e8baff0eca373e6e4266efa762da?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\/f4c013ebf7008223382b8a49203e6d354677e8baff0eca373e6e4266efa762da?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Mahesh Singh"},"url":"https:\/\/webkul.com\/blog\/author\/mahesh721\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/68407","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\/69"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=68407"}],"version-history":[{"count":8,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/68407\/revisions"}],"predecessor-version":[{"id":518010,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/68407\/revisions\/518010"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/66844"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=68407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=68407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=68407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}