Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

i tried following but didn't worked for me:

{{ console.log(varible) }}

like image 853
HDB Avatar asked Sep 17 '14 06:09

HDB


1 Answers

the following worked fine on the front end for me:

If you want to log "Cabin" as a string you can use

<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)

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(); 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!

like image 50
atomboyd Avatar answered Sep 23 '22 03:09

atomboyd