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.48k stars 635 forks source link

如何在 <script> 标签中使用变量 #1371

Open orochitian opened 2 years ago

orochitian commented 2 years ago

你好! 如何在页面的script标签中使用渲染后的变量。 比如我可能会动态的渲染一些图表,这些图表的初始化方法就在当前页面中。 没有在示例中找到使用的方法。 我自己是这么写的: chart.render({ data: '{{ chart.data }}' }) 这样写会有问题,如果data是:[1, 2, 3, 4] 实际页面渲染出来变成了:data: '1,2,3,4' 并且,如果我传入一个稍微复杂的对象,就会被解析为 [Object Object]

ogonkov commented 2 years ago

try dump filter

Maconzhang commented 2 years ago

try dump filter

how to use? for example?

ogonkov commented 2 years ago

My link have usage examples