Created
October 21, 2019 13:36
-
-
Save LucasCalazans/15574e7e6cb0cc94bea4d240368c4827 to your computer and use it in GitHub Desktop.
Create HTML components with JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | |
})); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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