{"id":63270,"date":"2016-10-26T18:31:42","date_gmt":"2016-10-26T18:31:42","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=63270"},"modified":"2016-11-21T07:02:51","modified_gmt":"2016-11-21T07:02:51","slug":"jquery-templates-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/","title":{"rendered":"Create JQuery Templates in Magento2"},"content":{"rendered":"<p>We can use jQuery templates in Magento2 and you don&#8217;t need to include any third party library for that.<\/p>\n<h2>JQuery Templates in Magento2<\/h2>\n<p>First of all you need to define a template. And then you can use it by &#8216;<strong>mage\/template<\/strong>&#8216; in js file.<\/p>\n<p>Here i am creating template for some employee information.<\/p>\n<pre class=\"brush:xml\">&lt;script id=\"employee-template\" type=\"text\/x-magento-template\"&gt;\r\n   &lt;ul&gt;\r\n        &lt;li&gt;\r\n           Employee Id : &lt;%- data.id %&gt;\r\n        &lt;\/li&gt;\r\n        &lt;li&gt;\r\n           Employee Name : &lt;%- data.name %&gt;\r\n        &lt;\/li&gt;\r\n        &lt;li&gt;\r\n           Employee Salary : &lt;%- data.salary %&gt;\r\n       &lt;\/li&gt;\r\n   &lt;\/ul&gt;\r\n&lt;\/script&gt;<\/pre>\n<p>Now include javascript code.<\/p>\n<pre class=\"brush:js\">&lt;script&gt;\r\nrequire([\r\n    \"jquery\",\r\n    \"mage\/template\"\r\n    ], function ($, template) {\r\n        var employeeData = [\r\n                            {\"id\":\"101\",\"name\":\"John\",\"salary\":\"50000\"},\r\n                            {\"id\":\"102\",\"name\":\"Paul\",\"salary\":\"30000\"},\r\n                            {\"id\":\"103\",\"name\":\"Peter\",\"salary\":\"45000\"}\r\n                        ];\r\n        $.each(employeeData, function() {\r\n            var employeeTemplate = template('#employee-template');\r\n            var employee = employeeTemplate({\r\n                                data: {\r\n                                    name: this['name'],\r\n                                    id: this['id'],\r\n                                    salary: this['salary']\r\n                                }\r\n                            });\r\n            $('#employee').append(employee);\r\n        });\r\n    });\r\n&lt;\/script&gt;<\/pre>\n<p>Finally define a html element where you want add and display this data.<\/p>\n<pre class=\"brush:xml\">&lt;div id =\"employee\"&gt;&lt;\/div&gt;<\/pre>\n<p>So the output of this snippet will be same as screenshot.<br \/>\n<img decoding=\"async\" alt=\"JQuery Templates\" class=\"alignnone size-full wp-image-63271\" src=\"http:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/template.png\" width=\"958\" height=\"301\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/template.png 958w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/template-250x79.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/template-300x94.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/template-768x241.png 768w\" sizes=\"(max-width: 958px) 100vw, 958px\" loading=\"lazy\" \/><\/p>\n<p>You can create and use any jquery template same as i did here.<\/p>\n<p>If you have any query, please comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We can use jQuery templates in Magento2 and you don&#8217;t need to include any third party library for that. JQuery Templates in Magento2 First of all you need to define a template. And then you can use it by &#8216;mage\/template&#8216; in js file. Here i am creating template for some employee information. &lt;script id=&#8221;employee-template&#8221; type=&#8221;text\/x-magento-template&#8221;&gt; <a href=\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":21,"featured_media":61510,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79,302],"tags":[3878,3877,2070],"class_list":["post-63270","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery","category-magento2","tag-jquery-template-in-magento-2","tag-jquery-templates","tag-magento2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to create and use jQuery Templates in Magento2<\/title>\n<meta name=\"description\" content=\"How to use jQuery Templates in Magento2, Create jQuery Templates in Magento2, jQuery templating in Magento2, Magento2 jQuery Templates\" \/>\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\/jquery-templates-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create and use jQuery Templates in Magento2\" \/>\n<meta property=\"og:description\" content=\"How to use jQuery Templates in Magento2, Create jQuery Templates in Magento2, jQuery templating in Magento2, Magento2 jQuery Templates\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/jquery-templates-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:author\" content=\"https:\/\/www.facebook.com\/rahul0989\" \/>\n<meta property=\"article:published_time\" content=\"2016-10-26T18:31:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-11-21T07:02:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.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=\"Rahul Mahto\" \/>\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=\"Rahul Mahto\" \/>\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\/jquery-templates-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/\"},\"author\":{\"name\":\"Rahul Mahto\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/3002e6bca8362f6cf1c61b2663496c4f\"},\"headline\":\"Create JQuery Templates in Magento2\",\"datePublished\":\"2016-10-26T18:31:42+00:00\",\"dateModified\":\"2016-11-21T07:02:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/\"},\"wordCount\":107,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\",\"keywords\":[\"jQuery Template in Magento 2\",\"jQuery Templates\",\"Magento2\"],\"articleSection\":[\"jQuery\",\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/\",\"name\":\"How to create and use jQuery Templates in Magento2\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\",\"datePublished\":\"2016-10-26T18:31:42+00:00\",\"dateModified\":\"2016-11-21T07:02:51+00:00\",\"description\":\"How to use jQuery Templates in Magento2, Create jQuery Templates in Magento2, jQuery templating in Magento2, Magento2 jQuery Templates\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\",\"width\":825,\"height\":260,\"caption\":\"Ui Component Form\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create JQuery Templates 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\/3002e6bca8362f6cf1c61b2663496c4f\",\"name\":\"Rahul Mahto\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b0def172ef24ea3f7319500afbb65af8012023ba5c143982a4c958b2fb58ee0d?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\/b0def172ef24ea3f7319500afbb65af8012023ba5c143982a4c958b2fb58ee0d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Rahul Mahto\"},\"sameAs\":[\"http:\/\/webkul.com\",\"https:\/\/www.facebook.com\/rahul0989\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/rahul\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create and use jQuery Templates in Magento2","description":"How to use jQuery Templates in Magento2, Create jQuery Templates in Magento2, jQuery templating in Magento2, Magento2 jQuery Templates","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\/jquery-templates-magento2\/","og_locale":"en_US","og_type":"article","og_title":"How to create and use jQuery Templates in Magento2","og_description":"How to use jQuery Templates in Magento2, Create jQuery Templates in Magento2, jQuery templating in Magento2, Magento2 jQuery Templates","og_url":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_author":"https:\/\/www.facebook.com\/rahul0989","article_published_time":"2016-10-26T18:31:42+00:00","article_modified_time":"2016-11-21T07:02:51+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","type":"image\/png"}],"author":"Rahul Mahto","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Rahul Mahto","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/"},"author":{"name":"Rahul Mahto","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/3002e6bca8362f6cf1c61b2663496c4f"},"headline":"Create JQuery Templates in Magento2","datePublished":"2016-10-26T18:31:42+00:00","dateModified":"2016-11-21T07:02:51+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/"},"wordCount":107,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","keywords":["jQuery Template in Magento 2","jQuery Templates","Magento2"],"articleSection":["jQuery","Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/","url":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/","name":"How to create and use jQuery Templates in Magento2","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","datePublished":"2016-10-26T18:31:42+00:00","dateModified":"2016-11-21T07:02:51+00:00","description":"How to use jQuery Templates in Magento2, Create jQuery Templates in Magento2, jQuery templating in Magento2, Magento2 jQuery Templates","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/jquery-templates-magento2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","width":825,"height":260,"caption":"Ui Component Form"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/jquery-templates-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Create JQuery Templates 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\/3002e6bca8362f6cf1c61b2663496c4f","name":"Rahul Mahto","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b0def172ef24ea3f7319500afbb65af8012023ba5c143982a4c958b2fb58ee0d?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\/b0def172ef24ea3f7319500afbb65af8012023ba5c143982a4c958b2fb58ee0d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Rahul Mahto"},"sameAs":["http:\/\/webkul.com","https:\/\/www.facebook.com\/rahul0989"],"url":"https:\/\/webkul.com\/blog\/author\/rahul\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/63270","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\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=63270"}],"version-history":[{"count":10,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/63270\/revisions"}],"predecessor-version":[{"id":65077,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/63270\/revisions\/65077"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/61510"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=63270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=63270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=63270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}