1
votes

I have following twig block in template which extends main layout:

{% block abc %}
    {{ name }}
{% endblock %}

next I have a head block in the same template. I want to pass block abc as template for twig.js:

{% block head %}
<script type="text/html" id="template-abc">
     {{ blocksource('abc') }}
</script>
{% endblock %}

so the rendering result is: {{name}}

How can I do this?

I tried building "blocksource" function in twig extension, but I don't know how to access block source form here.

function blocksource( Twig_Environment $env, $blockname) {
    $source = ???;
    return $source;
}
1
So you want the raw value of the abc block? In other words, you don't want Twig to interpret {{ name }}?A.L
yes, I want to use same template in symfony2 twig template and also in client side using javascript and twig.jscodez

1 Answers

-1
votes

Use verbatim tag, it will do what you want.

{% verbatim %}
    {{ things_you_want_to_show_as_twig_template }}
{% endverbatim %}

Everything inside this tag will not be interpreted by twig engine.

You can read more on that in twig documentation.