diff --git a/_layouts/payment.html b/_layouts/payment.html index af3ff98..b3a72e3 100644 --- a/_layouts/payment.html +++ b/_layouts/payment.html @@ -16,6 +16,6 @@ layout: default data-controller="cart-payment-methods" data-cart-payment-methods-next-url="{{ site.confirmation.url }}" data-cart-payment-methods-back-url="{{ site.shipment.url }}" - data-cart-payment-methods-template="assets/templates/payment_methods.html"> + data-cart-payment-methods-template="payment_methods"> diff --git a/_packs/controllers/cart_confirmation_controller.js b/_packs/controllers/cart_confirmation_controller.js index 08e5287..0faf726 100644 --- a/_packs/controllers/cart_confirmation_controller.js +++ b/_packs/controllers/cart_confirmation_controller.js @@ -12,7 +12,6 @@ export default class extends CartBaseController { if (!this.template) return if (this.storage.cart) { - const order = this.cart.data.attributes const products = this.products const site = await this.site() @@ -29,16 +28,14 @@ export default class extends CartBaseController { } render (data = {}) { - fetch(this.template).then(r => r.text()).then(template => { - this.engine.parseAndRender(template, data).then(html => this.orderTarget.innerHTML = html) - }) - } - - get template () { - return this.element.dataset.template + this.engine.parseAndRender(this.template, data).then(html => this.orderTarget.innerHTML = html) } get clear () { return this.element.dataset.clear } + + get template () { + return window.templates[this.element.dataset.template] + } } diff --git a/_packs/controllers/cart_payment_methods_controller.js b/_packs/controllers/cart_payment_methods_controller.js index 788012a..48f02e9 100644 --- a/_packs/controllers/cart_payment_methods_controller.js +++ b/_packs/controllers/cart_payment_methods_controller.js @@ -25,8 +25,7 @@ export default class extends CartBaseController { } async render (data = {}) { - const request = await fetch(this.data.get('template')) - const template = await request.text() + const template = window.templates[this.data.get('template')] this.element.innerHTML = await this.engine.parseAndRender(template, data) diff --git a/_packs/controllers/cart_shipping_controller.js b/_packs/controllers/cart_shipping_controller.js index d78d906..975663f 100644 --- a/_packs/controllers/cart_shipping_controller.js +++ b/_packs/controllers/cart_shipping_controller.js @@ -102,8 +102,7 @@ export default class extends CartBaseController { } async render (data = {}) { - const request = await fetch(this.data.get('template')) - const template = await request.text() + const template = window.templates[this.data.get('template')] this.methodsTarget.innerHTML = await this.engine.parseAndRender(template, data) this.ratesTarget.addEventListener('formdata', event => this.processShippingRate(event.formData)) diff --git a/_packs/controllers/notification_controller.js b/_packs/controllers/notification_controller.js index edb3299..4ef5456 100644 --- a/_packs/controllers/notification_controller.js +++ b/_packs/controllers/notification_controller.js @@ -24,15 +24,6 @@ export default class extends Controller { this.show() } - /* - * Gets the template path from a name - * - * @return [String] - */ - template (name) { - return this.data.get('templates') + name + '.html' - } - /* * Shows the notification */ diff --git a/_packs/controllers/order_controller.js b/_packs/controllers/order_controller.js index 5e8edb6..442e12e 100644 --- a/_packs/controllers/order_controller.js +++ b/_packs/controllers/order_controller.js @@ -43,9 +43,9 @@ export default class extends CartBaseController { * Download the item template and render the order */ render (data = {}) { - fetch(this.data.get('itemTemplate')).then(r => r.text()).then(template => { - this.engine.parseAndRender(template, data).then(html => this.cartTarget.innerHTML = html) - }) + const template = window.templates[this.data.get('itemTemplate')] + + this.engine.parseAndRender(template, data).then(html => this.cartTarget.innerHTML = html) } /* diff --git a/assets/templates/cart.html b/assets/templates/cart.html index 8c77090..6c3ecca 100644 --- a/assets/templates/cart.html +++ b/assets/templates/cart.html @@ -1,3 +1,4 @@ +{%- raw -%} {% for product in products %}