I am using Marionette
for my app development. I am loading controllers by dynamically from routes
. works fine.
once the controller loaded, It calls appropriate layout. for ex. loginController calls the loginLayout.
I have a single layouts.html
, where all my layout nested. i am using requirejs and getting the layouts.html
using:
"text!./layouts.html"
but from the layouts.html, I can't able to get my template. my layout.html is:
<script type="text/template" id="loginTemplate">
<section class="login">
<p>I am only for login purpose</p>
</section>
</script>
<script type="text/template" id="contactTemplate">
<header>
</heder>
<section class="login">
<p>I am only for login purpose</p>
</section>
<footer></footer>
</script>
I am trying like this:
define([
"jQuery","underscore",
"backbone","marionette",
"text!./layouts.html"
],
function($,_,Backbone,Marionette,template){
var loginLayout = Backbone.Marionette.Layout.extend({
template:$(template,"#loginTemplate"), //i am not getting the template from layouts.html
regions:{
content:'section'
},
initialize:function(){
console.log(this.template)
},
render:function(view){
$(this.content.el).html(view);
}
});
return loginLayout;
}
);
why I am not able to get my template? and what is the correct way to get it? any one help me please?
Thanks in advance.
Here's one option:
And then in your view, you'd use it like this:
Another option would be to only include the
layout.hml
file in a configuration file, then you won't need to call it in each file:Then you'd just have:
The benefit of this is that you can also throw in another check for it to check the document or anything else that you'd want to find that template within.