Wednesday, April 25, 2018

Magento 2 - how to load JS template from filesystem in jquery widget

Leave a Comment

For example, native Magento theme-frontend-blank\web\js\navigation-menu.js has such code:

$.widget('mage.navigationMenu', {     options: {     ...         collapsableDropdownTemplate:             '<script type="text/x-magento-template">' +                 '<li class="level0 level-top more parent">' +                     '<div class="submenu">' +                         '<ul><%= elems %></ul>' +                     '</div>' +                 '</li>' +             '</script>' 

And then they do

        this.collapsableDropdown = $(             mageTemplate(                 this.options.collapsableDropdownTemplate,                 {elems: this.elemsToCollapseClone}             )         ); 

Is it possible to do something like this

collapsableDropdownTemplate: getTemplate(some_relative_path_to_template) ? instead of

        collapsableDropdownTemplate:             '<script type="text/x-magento-template">' +                 '<li class="level0 level-top more parent">' +                     '<div class="submenu">' +                         '<ul><%= elems %></ul>' +                     '</div>' +                 '</li>' +             '</script>' 

My template is a little bit bigger and I want to allow frontend developers to modify it.

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment