Dynamic template rendering in Angular - django

Can we render template dynamically from DB?
in this template, I'm going to use angular event, string interpolation and directive.
Do we have any other option instead of Angular compiler??
Currently we have old process or code...

Related

Render Django formsets with AngularJS?

I want to move some parts of a main template into partials which shall not need django rendering (i.e. pure html/js) and use them in a ng-view in the main template.
However, the partials have Django formsets (using crispy) in them i.e useless without Django rendering.
Moreover, I do not want to write the complete formset HTML by hand.
How can I do this?
Maybe you have a less or sass file too. This file, like your form, it's unusable without preprocessing.
Review code from https://www.djangopackages.com/grids/g/asset-managers/ for inspiration and look at https://docs.djangoproject.com/en/dev/howto/static-files/ to learn how to do it.
Hard part is not do it because its easy make a static finder. Hard part is do it in development staging in a transparent way.
You can request your partials from the server and put them into the $templateCache yourself using the filename as a key.
This way, when a partial .hmtl file is request, it will get the django rendered HTML.
$http.get('myForm.html', {cache:$templateCache});
You'll want to eagerly load these partial templates, as if the partial template is not in the cache, then it'll request the static html.
Hope this helps

Dynamically rendering Polymer Web component layouts - What are recommended approaches?

Dynamically rendering Polymer Web component layouts - What are recommended approaches?
Is there any sort of "Polymeric" way to do layout template rendering. I have a set of reusable Polymer tags that can be configured using attributes. I want to do higher level dynamic rendering of these tags based on data that gets fed into the main page. (e.g. for example loop over the Polymer tags and render N-number of templates based on an array customers, orders, etc.)
Right now I'm doing this using John Resig's micro-templating and I suppose any template engine would work (browser or server-side). Just wondering if there's a Polymer-specific way to render the naked Web components based on dynamic data in the DOM without going back to my old approaches (e.g. using another template engine to render polymer tags in the DOM).
What are the recommended approaches to handle data-driven layout of Polymer tags?
Try the is="auto-binding" template attribute.
<template is="auto-binding"></template>
http://www.polymer-project.org/docs/polymer/databinding-advanced.html#bindingoutside
This gives you Polymer data binding without a full-blown custom element. The other option is to make another Polymer "customers" or "page" element that represents the collection you're rendering.

Render Ember.js Templates using Underscore.js

I'm trying to render the templates in ember.js on HTML. Can the templates in ember.js be rendered using underscore.js?
Technically it may be possible but you should use handlebars for the templates. In Ember the integration of handlebars is deep into the view layer. The also have the data binding system built on top it (metamorph.js).
The ember team is also working on HTMLBars which should speed up rendering and simplify the data binding system. The current word right now is that, upgrading handlebars template to HTMLBars will be very simple maybe even without any modification.
This post should give you some more useful information on using other templating engines.

include views vs render templates in grails

What is the technical differences between render a template and include a view in grails?
You generally render a template (from a controller) as part of an AJAX request when you're updating only part of a page. I don't know what you mean by 'include a view'. If you mean render a template from a GSP then it's generally just a convenient way of reusing pieces of your presentation within a view.
So if I have a template that contains a login form, I may want to include that template in several different layouts/pages.
If I have a template that contains search results I may want to render the template from a controller in response to an AJAX request that occurs when the user scrolls to the end of my current set of results or the user updates some search criteria.

How can I put a block of dynamically generated content into a django template?

I want to include things like twitter status, or delicious tags, in my django templates.
These things are dynamic, yet regular. How would this be done?
There are a number of ways to handle this, so you can choose a method that best matches your own personal style or requirements:
Template context variable: as answered by Alex you can put your content into a context variable that is included in the context of every template created by every view. Django even provides a mechanism for doing this automatically, called a context processor. Pros: very straightforward. Cons: won't dynamically refresh new content on client browsers.
AJAX dynamic loading: as mentioned by Alex and Dave you can dynamically load your content using AJAX methods. As an example using jQuery, you would put a placeholder in your template something like <div id="twitterfeed"></div> and then in a javascript block in your template put $("#twitterfeed").load("{% url twitterfeed %}"); where twitterfeed is a url so named in your urls.py. Pros: will dynamically update browsers. Cons: can be tricky if you don't know Javascript.
Inclusion tag: Django provides a type of template tag called an inclusion tag, which is basically a custom template tag that can render dynamic content. In a way it's similar to a context variable, except your code to generate the content will only be called when you use the custom template tag in your template instead of being called for every view. Another benefit is the content is generated from a template of its own. You could do this with a normal context variable of course, but it's not as clean (IMHO) as using an inclusion tag. Pros: very straightforward, clean. Cons: won't dynamically refresh new content on client browsers.
The simplest approach is to use {{ mycontent }} in your template (where you want the dynamically generated content to appear) and put the correspondence between mycontent and its value in the context you use to render the template -- i.e., the most fundamental part of django's templating.
If what you mean is that you want Ajax support whereby Javascript on the page continuously refreshes such content according to what the server wants it to be at any given time, I suggest looking into dojango, the Dojo/Django integration project -- it's not yet as fully mature as each of Dojo and Django are on their own (not version 0.4 yet), but it is already usable and useful.
A common technique is to leave a placeholder div in the generated content, then fill the div in on the client side via an AJAX call from Javascript that you include in the page.
That gives you the benefit of having a cacheable (fast loading) primary page, with separate dynamic bits. Depending on how live you want the dynamic bits, you can can even cache them for shorter durations.