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) }}
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With