i believe you get this error, because your macro generates line breaks.
try 1st:
{% macro my_macro(...) %}
{% spaceless %}
...
{% endspaceless %}
{% endmacro %}
try 2nd :
$('#myid').append('{{ my_macro()|e('js') }}');
Question
I'm generating HTML code such as this
<li class="myclass"><p>bla bla</p><p> bla bla</p></li>
with a twig macro. I'd like to use this code with JS Jquery to append it somewhere, like this:
$('#myid').append('{{ my_macro() }}');
TWIG seems to be generated before JS and messing up my code
SyntaxError: unterminated string literal
$('#COA_Table').append('
Is that possible somehow or should I just create an hidden element somewhere in my page and append it by copying it ?
Solution
i believe you get this error, because your macro generates line breaks.
try 1st:
{% macro my_macro(...) %}
{% spaceless %}
...
{% endspaceless %}
{% endmacro %}
try 2nd :
$('#myid').append('{{ my_macro()|e('js') }}');