Override a portion of an extends template
You could define a variable in you child template:

{% set bodyAttributes = 'onload="load()" onunload="GUnload()"' %}


And then output the value in your parent _layout.html template. Use the is defined test, so that not every template extending this file has to have that variable defined. I'm using ternary syntax here, to keep the code nice and lean:

&lt;body {{ bodyAttributes is defined ? bodyAttributes : '' }}&gt;


As I generally like to have as few logic in my Twig output tags as possible (in particular when they output classes and attributes to already cluttered HTML tags), I would write that code like so:

{% set bodyAttributes = bodyAttributes is defined ? bodyAttributes %}

&lt;body {{ bodyAttributes }}&gt;