5

I want to display array results in my database on the frontend using EJS.

So I have the following code:

 var tagss = ["<%tags%>"]  
    <% for(var i=0; i<tagss.length; i++) { %>

            <a href='<%= tagss[i] %>'> <%= tagss[i] %> </a>

            </a>

    <% } %> 

But error message keeps telling me that tagss is undefined

Here is the full message:

full message:


ReferenceError: C:\xampp\htdocs\meme.africa\views\pages\meme.ejs:171
    169| 

    170|  var tagss = ["<%tags%>"]  

 >> 171|     <% for(var i=0; i<tagss.length; i++) { %>

    172|         

    173|             <a href='<%= tagss[i] %>'> <%= tagss[i] %> </a>

    174|                


tagss is not defined

Please, what am I doing wrong?

2
  • 1
    The stuff inside <% %> is JS. The rest is the template. You need to make it code, not template. Like you did everywhere else you used it. Commented May 29, 2018 at 17:18
  • 1
    How? Can you put it in code? Commented May 29, 2018 at 18:56

1 Answer 1

6

I think you can declare it like this

<% var myTags = []; %>

I hope it's not too late

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.