Skip to content

Instantly share code, notes, and snippets.

@LucasCalazans
Created October 21, 2019 13:36
Show Gist options
  • Save LucasCalazans/15574e7e6cb0cc94bea4d240368c4827 to your computer and use it in GitHub Desktop.
Save LucasCalazans/15574e7e6cb0cc94bea4d240368c4827 to your computer and use it in GitHub Desktop.
Create HTML components with JS
define([
'mage/template',
'text!Magento_Theme/templates/product-card-template.html'
], function(
mageTemplate,
productCardTemplate
) {
const productElement = document.getElementById('product-container');
productElement && (productElement.innerHTML = mageTemplate(productCardTemplate, {
id: 1568,
name: 'Product name',
image: 'product/image.png',
price: '$9.99',
}));
});
<!-- Magento_Theme/web/templates/product-card-template.html -->
<li class="product-item" data-id="<%- id %>">
<div class="product-item-info">
<% if (!!image) { %>
<span class="product-item-photo">
<img class="product-item-image" src="<%- image %>">
</span>
<% } %>
<div class="product-item-details">
<h3 class="product-item-name"><%- name %></h3>
<span class="product-item-price"><%- price %></span>
</div>
</div>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment