I have this ItemView
in Marionette
:
App.View.MovieListItem = Marionette.ItemView.extend({
tagName: 'li',
className: 'movie',
model: App.Model.Movie,
id: function() {
return 'movie-'+this.model.get('imdb')
},
initialize: function () {
this.render();
},
template: _.template('<a href="javascript:;">'+
'<i class="fa fa-eye fa-3"></i>'+
'<span class="cover"></span>'+
'<strong><%= title %></strong>'+
'<small><%- year %></small>'+
'<small2>Cached</small2>'+
'</a>'),
});
And i want to know if it's possible to create the template dynamically?
Because some time i want(Base on method that check something) to remove the small2
tag.
Marionette has a function called getTemplate
which can be used to return dynamic templates.
Example:
App.View.MovieListItem = Marionette.ItemView.extend({
tagName: 'li',
className: 'movie',
model: App.Model.Movie,
id: function() {
return 'movie-'+this.model.get('imdb')
},
initialize: function () {
this.render();
},
getTemplate: function(){
if(condition){
return _.template(/* HTML STRING */);
}else{
return _.template(/* ANOTHER HTML STRING */);
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With