0

I have a function from which i d like to return a small html snippet.

in the page.ejs <% for(var i=0; i < studentList.length; i++) { %>

                <td> <%= rateStudent(studentList[i].metricArray)%> </td>

            </tr>
        <% } %>
</tbody>

somewhere in the page.js

function rateStudent(metricArray){
     // omitted

        return '<span class="label label-danger"> Zayif </span>';
    };

the function is called, everything works. But the function returns the snippet and i see it printed as text :) is it normal?

how can i return a div snippet from a ejs function?

<span class="label label-danger"> Zayif </span>

Thanks

Orkun
  • 6,998
  • 8
  • 56
  • 103
  • possible duplicate of [How to include html code in a view?](http://stackoverflow.com/questions/8547131/how-to-include-html-code-in-a-view) – Dave Newton Aug 19 '15 at 20:15
  • 3
    I believe you can make the HTML safe by changing the way ejs prints: `<%- rateStudent(studentList[i].metricArray)%>`. Note the dash instead of the equals in the opening EJS tag – Brennan Aug 19 '15 at 20:15
  • 1
    magic. that was it @Brennan thanks! – Orkun Aug 19 '15 at 20:16

0 Answers0