mde / ejs

Embedded JavaScript templates -- http://ejs.co
Apache License 2.0
7.7k stars 841 forks source link

How to pass data from main script to <script>tag when rendering ? #661

Closed rsa408 closed 2 years ago

rsa408 commented 2 years ago

In index.ejs I have a word cloud that is using wordcloud2.js @timdream.

<canvas id="canvas"></canvas>
            <script>
                WordCloud(document.getElementById('canvas'), {
                    list: <=%targetlist%>
}); 
            </script>

In the main script(app.js) which is using express the following code generates targetlist and after that index.ejs will render again. I try to send the targetlist from the main script to the front to generate word cloud.

for (const [key, value] of Object.entries(output.list)) {
               targetlist.push([`${key}`, value]);            
            }        
            response.render('index',{targetlist:targetlist});

it is not passing data to script tag.

mde commented 2 years ago

The Githubissues.

  • Githubissues is a development platform for aggregating issues.