I have a simple twig template that looks like this:

  set classes = [
    'region-' ~ region|clean_class,
    '' ~ region|clean_class,
    elements.system_main ? 'controller-page',

{% if content %}
  <div{{ attributes.addClass(classes) }}>
    {% if elements.system_main %}
      {{ elements.system_main }}
      {% set elements = elements|without('system_main') %}
    {% endif %}
    {{ content }}
{% endif %}

The main variable I am concerned with are content and elements. In the above I am trying to print elements.system_main before the rest of the content, and then remove it from the elements variable. But even though I do that it is still being printed out with the content variable.

I can't figure out why elements is being printed out at all, because the content variable only has the markup from my controller. But when I don't print the content variable it doesn't print any of the elements. How is it possible that elements.system_main can be printed out a second time after I have deleted it? I have used kint to debug the elements variable and it shows that system_main has successfully been deleted.

I am also unable to print content|without('system_main') because content is only markup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.