How to work with other templates like Django's template or mako template?

2,752 views
Skip to first unread message

luthur

unread,
Jun 16, 2013, 10:54:37 AM6/16/13
to polym...@googlegroups.com
It seems MDV works the same as what other templates do. 


Polymer render after the age load. Could be changed later.

Template render at the template render stage.And cannot changed. 

Eric Bidelman

unread,
Jun 16, 2013, 2:27:13 PM6/16/13
to luthur, polymer-dev
Hey Luthur,

It boils down to the type of app you want to write, one that is client driven vs. server driven. Most of the MVC frameworks today have taken what the server templating languages have done, and adopted it...making front-end development much more powerful. Polymer/MDV is focused on client-side development. 

If you had an "items" model from the server, your templating might look like this:

{% for item in items%}
  <my-element name="{{item.name}}"></my-element>
{% endfor %}

which would render from the server as:

<my-element name="One"></my-element>
<my-element name="Two"></my-element>
<my-element name="Three"></my-element>
...

The markup is static and harder to make dynamic updates to once it is servered to the client. Instead, you can leave the work up to the frontend, but still populate the data from the server (or use XHR to bring it in):

{% verbatim %}
<template repeat="{{item as items}}">
  <my-element name="{{item.name}}"></my-element>
</template>
{% endverbatim %}

<script>
  document.querySelector("template').model = {{items}}; // items here is filled by the server's template.
</script>

Note:
If you're using a server templating system like Django, there may be conflicts
with MDV's {{}}. Django in particular uses the same variable placeholder.

Django 1.5 has support for the verbatim tag. You can wrap your inlined element definitions in that:

If you're using an older version, people have created gists that you can reuse:

Hope this helps!
Eric


--
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

litt.f...@gmail.com

unread,
May 20, 2016, 6:11:36 AM5/20/16
to Polymer, kongp...@gmail.com
Just thought I'd post a solution for django developers here. It does require some stricter use of template tags, but works quite nicely.
I've posted it as a answer here: http://stackoverflow.com/a/37343856/433267
Reply all
Reply to author
Forward
0 new messages