javascript – How to pass nunjucks variable as Js function parameter-ThrowExceptions

Exception or error:

I’m using javascript to read JSON data from file, and then render it using nunjucks.
At some point, I want to apply a function on a button click, and this function takes a nunjucks variable as argument.

My question is how to pass the nunjucks variable as an argument to my function?

Here is the concerned part of my code.

Thank you

index.js

.....
res.render('view.html', {items});

view.html

<script type="text/javascript">
  function openArticlePage(arg) {
    alert(arg)
  }
</script>
<body>
{% for item in items %}
    <p>{{item.title}}</p>
    <button class="btn" onclick="openArticlePage({{item}});">Read More</button>
</body>
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *