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.
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.
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.
Related
Site has traditional template structure elements: header, content, footer. And almost all pages of the site has such structure. But 404-page doesn't have the header.
So my question is: Is there some clean way to set unique application template for 404-page?
Of course, I can add {{ partial 'header' }} to the begining of all templates, beside 404-page, but I hope there is right way to do this ...
Thanx
P.S. Sorry for my English
P.S.S. EmberJS v1.9.1
Whilst not changing the application template name, you can change the content of the application template from route-to-route by observing the currentPath property of the application controller and using an {{#if}} helper in the application template to hide and show the header.
This is a cleaner approach than changing the application template name because you won't have to rerender any views.
Here is a working JS Bin.
I have a fairly complex text that I need to generate programmatically for display within an ember template. So far I have put this text construction into a controller.
Unfortunately, the text also needs to contain hyperlinks to other pages within the same ember app. When I just insert a href links into the text, ember does not recognize those links and triggers a full page reload upon following the link.
Is there a way to invoke ember's linkTo helper from within a controller?
I could also try to put this into a template, but the logic is fairly complex and emblem is somewhat limiting in this regard.
You can use an action in the template and inside the action you can do this.transitionToRoute
http://emberjs.jsbin.com/uMeQAvuk/1/edit
BTW, the only reason it should be causing a full page refresh is if something is different in the base url (before the hash) than the current page, or if it is doing some sort of page refresh instead of just an anchor tag.
I want to use the Django comments app in my modal diagram, specifically the tag:
{% comments item %}
Which brings up a place for users to submit comments and view comments on a model object (in my case the variable is called item).
Is it possible to use this in a modal window, and if so, how? I imagine it would need javascript/jquery to pass the variables, etc. but have no idea where to start on that.
I don't understand why using tags in a modal window would be any different to using them anywhere else. Either your window is built alongside the elements in the existing page, in which case you use template tags there, or its built via Ajax, in which case you use template tags when you render the Ajax response.
I have a page which is for album/picture management with 2 sections: Albums and Pictures.
When an album is selected the pictures block needs to change via AJAX to reflect the album selected.
This means the rendered pictures block needs to be provided to the Albums page as well as be available as it's own View for the AJAX source.
I understand I could solve this by making the pictures block always render from AJAX even when the album page loads, however I would like to deliver the default album pictures within the initial page load if possible. In order to do that, I'd like to render the pictures block via the same template in the Album page view as is used for the Picture AJAX View.
I'm only familiar with providing templates as a template_name property within an TemplateView object.
I guess I could simply call an instance of PictureView using inclusion_tag, and pull the data I need out of the render_to_response (I haven't tried this yet, I'm just theorizing) however that seems a bit dirty to me. I'm wondering if there's a more elegant solution to this problem?
Thanks!
jQuery, Django templates, JS templating and backbone.js should tie this together.
I would suggest having a dedicated template for the Pages block. Include this template in the Django template for your page.
For dynamic updates use a JS templating library such as included in underscore.js or moustache.js. You can change the template demlimiters used so that they are the same as djangos.
Include the raw Pages block template into a javascript template block - use the django ssi tag.
Use django-tastypie to set up an api that returns the data for Photos as JSON. Your template library can then use data to fill in the template in the JS template block and you can then replace the Photo block with this rendered HTML. Use of backbone.js should ease the tying of DOM elements and JS events.
If I understand your question correctly, I did something similar once with the subsection having its own template file, which only describes that one section of the page. I used the include tag to include it into the page template, so it loaded when the page did and then rendered that template with updated values and replaced it on the page with AJAX when the content was meant to change.
Is that an option for you?
I am working on a website. On the Homepage, I want to show the posts in the center and show famous tags on the right side of the page. Now, posts and tags are two different apps and their views/tempaltes are calculated/generated in two separate functions.
How can I show what I want on my Homepage keeping my mind that its two different views being called. As far as I understand, I can only call a single view to show my homepage.
This must be possible but I am unable to understand this. Any help will be much appreciated.
I think you need to create a custom template tag that in this case called: Inclusion tags
You can look into writing a custom template tag for the tags. That way the tag logic can stay in the right application.
It depends how these different apps render the templates. If they just render the template without extending from a base template you could simply use AJAX to load all the content into your homepage.
If not, then there is no other way than writing a custom solution for this. This could be an extension to your views, a custom template tag as already mentioned or something else according to what exactly you need.