In a handlebars template, can I access a handlebar parameter inside a script tag like
<script>
var aList = {{list}}
</script>
The template is called from express
with
response.render('template', {list: [1, 2, 3]})
In a handlebars template, can I access a handlebar parameter inside a script tag like
<script>
var aList = {{list}}
</script>
The template is called from express
with
response.render('template', {list: [1, 2, 3]})
You can use a hidden input in your html that contains the value you want and then get that using document.getElementById in the script tag.
<input type = "hidden" id = "thingIWant" value = {{list}} />
<script>
var aList = document.getElementById("thingIWant").value;
</script>
Express is a back-end framework, so you won't be able to render front-end templates (that is, templates within <script>
tags) from Express.
To use handlebars template with Express, you can use a package like express-handlebars; the documentation for that package will take you step-by-step through the setup process.