Updating Views with New Data

47 views
Skip to first unread message

JP

unread,
Sep 5, 2014, 6:06:40 PM9/5/14
to nunj...@googlegroups.com
Hello,

I just started using Nunjucks in a project and am really enjoying it! I have one question, which I assume will be obvious to some, that I can't seem to figure out.

Assume the following scenario:

===== Javascript object:


someObj
= {
  items
: [1,2,3,4,5]
}



===== Template (someFile.html):


{% for item in items %}
 
{{item}}
{% endfor %}



===== Initial render call


nunjucks
.render('someFile.html', someObj, function(err, res) {
  $
("body").html(res);
});



This will render the page printing the following to the body of the HTML page:

12345


Here's my question: If I want to update the rendered template with new data, is there anyway to accomplish that?

For example, if I were to open the Javascript console and update someObj's items key like so:

someObj.items = [6,7,8,9]

How can I get the template to reflect the object's updated value? Is there a method I can call? Do I need to re-render the template?

I really appreciate any help I can get. Thank you.

JP

Piotr Zaborowski

unread,
Sep 8, 2014, 3:40:38 AM9/8/14
to nunj...@googlegroups.com
Hi JP,

AFAIK Nunjucks does not keep a binding to the rendered html. If you want to update it you'll have to re-render.

Cheers
Reply all
Reply to author
Forward
0 new messages