mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.55k stars 638 forks source link

How update variable value in script inner. #1274

Closed PHPJourney closed 4 years ago

PHPJourney commented 4 years ago

I'm try use nunjucks render variable update data in script inner.

The framework from thinkjs..

I don't understand variable quote and set method in my project.

The View template variable update data and real-time show this page. no need refresh.

like vue data bind.

If i want everytime update data to this page. real-time render and change it. How can do that?

I'm in script tags inner call setInterval in 1 seconds .

and get the nunjucks variable. parse the object.

and object.push new data.

set data to nunjucks variable, why not update page data.

my sample code

setInterval(function(){
        var type = Math.round(Math.random()*2);
        var message = JSON.parse('{{ message| dump | safe }}');
        message.push({
            type: ['info', 'error', 'warning'][type],
            content: 'Socket api concat object. this type value of '+ type
        });
        {% set message = message %}
        console.log(message);
    }, 1000);
PHPJourney commented 4 years ago

If my project create websocket connect . I need real-time print log to page. How bind variable.

or use Id Class append?

i'm waiting for your reply!!

fdintino commented 4 years ago

Hi. I'm unable to offer technical support on github issues for this project. As the sole maintainer, I barely have the time to respond to bug reports. You would probably have better luck asking on stack overflow.