0
votes

I want to know if it's possible to hide all the template view in html page.

I am using backbone and underscore to load templates like following

app.View.ShoppingPanelView = Backbone.View.extend({
    template: _.template($('#shopping-sideline').html()),

.....

and in my jsp page i do

<jsp:include page="includes/templates-shopping.jsp" />

Now i see using firebug that all my templates are visible.

enter image description here

is it possible somehow i hide the templates in final html page. The reason is the as you can see the templates contains the code and don't want to display how internal things are structured.

1
i guess no, but you can load templates on demand with requireJs, so the source on the template wont be visible in HTML - Evgeniy

1 Answers

0
votes

In my opinion it makes no sense working SPA. Why don't you load it when are really necessary?

You can Load a template only when it is necessary using the lazy load concept. Try to separate all of your template files inside html files and use !text to load then.

For example, let's suppose that you just want to display a view(or template) when some button is clicked, so your code will look like this.

events:
   "click #someButton": "showNewView"

showNewView:->
    require['pathToNewTemplateOrView'], (TemplateOrView)->
        view = new TemplateOrView()

This way your template or view will just be displayed when the button is clicked.

Another thing that I always avoid logic inside my templates, things like If statements. Try to do that inside your views, and make sure that your view are just reflecting what is on your model.

Hope it helps.