1

why twig code {% set code = code(_self) %} doesn't work in xml template.

<!-- src/Acme/DemoBundle/Resources/views/Demo/hello.xml.twig -->
<hello>
    <name>{{ name }}</name>
</hello>
{% set code = code(_self) %}

like it works in html template.

{% extends "AcmeDemoBundle::layout.html.twig" %}

{% block title "Hello " ~ name %}

{% block content %}
    <h1>Hello {{ name }}!</h1>
{% endblock %}

{% set code = code(_self) %}
8
  • What is supposed to do your custom Twig function code ? Commented Jan 8, 2014 at 9:30
  • {% set code = code(_self) %} is usefull in displaying Controller Code and Template Code used for the same route Commented Jan 8, 2014 at 11:55
  • And what do you mean by does not work ? You get an exception ? Commented Jan 8, 2014 at 12:18
  • @COil doesn't work means, its not showing the Controller Code and Template Code when used in xml template. No, i am not getting any exception. i just want to show those Codes as well when xml template is rendered. Commented Jan 8, 2014 at 12:24
  • Can you join the code of your code Twig function ? Commented Jan 8, 2014 at 12:25

1 Answer 1

1

Well it's not a native Twig extension it's an additional extension provided by the DemoBundle of the Symfony2 standard edition (https://raw.github.com/symfony/symfony-standard/master/src/Acme/DemoBundle/Twig/Extension/DemoExtension.php). I've just tested and it works but this code() Twig extension is only intended to be used in an HTML template not an XML one. If you show the source of you XML template you will see the output of your controller but it will not show up as the generated XML becomes invalid. If you really want the output, you can use this:

<?xml version="1.0" encoding="UTF-8"?>
<code>{{ code(_self) | escape }}</code>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.