문제

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 ?

도움이 되었습니까?

해결책

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') }}');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top