I had some working code where I used html_writer in Moodle. I wanted to pull that out and use a Moodle template with $OUTPUT->render_from_template() and my new mustache template.
Errors started showing up as the browser complains about "SyntaxError: expected expression, got '&'". The problem is that I am creating an array of label names and converting it to a json string via json_encode to pass to a JQuery parameter but Moodle appears to be using htmlspecialcharacters() when I use render_from_template() on the json string. So the browser sees [{"e;mylabel1"e;,. . . and doesn't know what to do with it.
I have tried several of the json_encode second parameter options like JSON_UNESCAPED_UNICODE. They don't correct the issue. I've tried just passing in an array created by PHP. I've tried manually creating a string which doesn't work. I get the wrong escaped literal message or that the second parameter is an array when it should be a string error messages.
So how do I accomplish this?
Here is the wrong rendering
hints: ["my course label 1","my course label 2","my course label 3","my course label 4 ","my course label 5"],
I need one of the following outputs:
hints: ['my course label 1','my course label 2','my course label 3','my course label 4 ','my course label 5'],
or
hints: ["my course label 1","my course label 2","my course label 3","my course label 4 ","my course label 5"],