[英]Nunjucks console log not working as node js template engine
I am new in node.js "nunjucks" templating, i have got most of the information available in nunjucks docs but i don't know how to console the variable init?我是 node.js“nunjucks”模板中的新手,我在 nunjucks 文档中获得了大部分可用信息,但我不知道如何控制变量 init?
i tried following but didn't worked for me:我尝试了以下但没有为我工作:
{{ console.log(varible) }}
the following worked fine on the front end for me: 以下对于我来说在前端工作正常:
If you want to log "Cabin" as a string you can use 如果要将“ Cabin”记录为字符串,可以使用
<script> console.log( "Cabin" )</script>
If you want to log a variable, try: 如果要记录变量,请尝试:
{% set thing=5 %}
<script> console.log({{ thing }})</script>
...which returns 5 (the number) ...返回5(数字)
EDIT: As Valorad pointed out below, if the 'thing' you're trying to point out is not a string, you may have to do some processing and add a few filters before the console.log(); 编辑:正如Valorad在下面指出的那样,如果您要指出的“事物”不是字符串,则可能必须进行一些处理并在console.log()之前添加一些过滤器; outputs the proper info in the console, such as:
在控制台中输出正确的信息,例如:
<script> console.log(JSON.stringfiy({{ thing }}))</script>
OR, more likely: 或者,更有可能:
<script> console.log('{{ data.page | dump | safe }}')</script>
Thanks Valorad for reporting back! 感谢Valorad回报!
<script>
console.log({{ surveyData | dump | safe}})
</script>
I would recommend using it this way.我建议以这种方式使用它。
dump(2)
indents the object to be readable. dump(2)
将 object 缩进为可读。
<script>console.log("data:", `{{ data | dump(2) | safe }}`)</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.