Chartjs-"<%=value%>" in javascript not ASP.net

1👍

You can put it in a string, kind of like escaping it.

The close tag doesn’t seem to work, so you could concatenate two strings, and use constants to make it slightly easier to read:

<%
     const string OPEN = "<%=";
     const string CLOSE = "%" + ">";
%>

legendTemplate : "<ul class=\"<%=OPEN%>name.toLowerCase()<%=CLOSE%>-legend...

Or do it in javascript instead, but this would make it more difficult to see in the source HTML:

    var OPEN = "<" + "%" + "=";
    var CLOSE = "%" + ">";

    legendTemplate: "<ul class=\"" + OPEN + "name.toLowerCase()" + CLOSE + "-legend... "

Another option would be to use a different representation for one of the characters, maybe for percent. You could do \045 or another representation (EDIT: Don’t use \045, use \x25 or \u0025 instead – looks like octal is getting phased out of javascript):

legendTemplate = "<ul class=\"<\x25=name.toLowerCase()\x25>-legend... "

Or probably the better answer, if you’re not using any server code in this particular piece of javascript, just move it out to a .js file.

Leave a comment