Marionette - How to set the template for Layout from html loading through requirejs? -


i using marionette app development. loading controllers dynamically routes. works fine.

once controller loaded, calls appropriate layout. ex. logincontroller calls loginlayout.

i have single layouts.html, layout nested. using requirejs , getting layouts.html using:

"text!./layouts.html" 

but layouts.html, can't able template. layout.html is:

    <script type="text/template" id="logintemplate">         <section class="login">             <p>i login purpose</p>         </section>     </script>     <script type="text/template" id="contacttemplate">     <header>      </heder>     <section class="login">         <p>i login purpose</p>     </section>     <footer></footer> </script> 

i trying this:

define([     "jquery","underscore",     "backbone","marionette",     "text!./layouts.html"     ],     function($,_,backbone,marionette,template){          var loginlayout = backbone.marionette.layout.extend({              template:$(template,"#logintemplate"), //i not getting template layouts.html              regions:{                 content:'section'             },             initialize:function(){                 console.log(this.template)             },             render:function(view){                 $(this.content.el).html(view);             }          });          return loginlayout;      } ); 

why not able template? , correct way it? 1 me please?

thanks in advance.

you can load template html instead of providing dom identifier defining marionette view template property function instead of string.

define([     'text!templates/my_template.html' ], function(     templates ) {      return marionette.view.extend({          template: function(data) {             return _.template($(templates).filter("#template_id").html())(data);         }      });  }); 

this looks element id "template_id" in my_template.html file, gets inner html of element , uses template, passing in template data.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -