title: Overriding parent variable in twig
body: <p>I have an extension that I am putting together with twig / PHP.</p>
  
  <p>My extension looks for a line like the following:</p>
  
  <pre><code>{% module 'blog' with {'controller':'controllers/posts.php', 'view':'templates/posts.html'} %}
  </code></pre>
  
  <p>Inside my token parser I look up the path for the controller (posts.php) and include the file - this is all working fine.</p>
  
  <p>Inside the "posts.php" file I want to override the $context or otherwise override the variables in the parent template I am extending, however, it seems that $context is not passed by reference and thus cannot be overwritten.</p>
  
  <p>My (base.html) template file looks like this (shortened for easier reading).</p>
  
  <pre><code>&lt;title&gt;{{meta.title}}&lt;/title&gt;
  {% block content %} Default  content {% endblock %}
  </code></pre>
  
  <p>My index.html (template that extends base.html) looks like this:</p>
  
  <pre><code>{% extends 'base.html' %}
  {% block content %}
  {% module 'blog' with {'controller':'controllers/posts.php', 'view':'templates/posts.html'} %}
  {% endblock %}
  </code></pre>
  
  <p>Inside "posts.php" I am (attempting) overriding of $context (which is actually the variables the template gets rendered with) like this:</p>
  
  <pre><code>$context['meta']['title'] = microtime(true);
  </code></pre>
  
  <p>And wrapping the entire functionality is obviously the render method (from Slimphp - simplified for brevity)</p>
  
  <pre><code>$twig-&gt;render('index.html', ['meta'=&gt;['title'=&gt;'Set from slim']]);
  </code></pre>
  
  <p>The meta.title variable is always set to "Set from slim" in the parent template, no matter what I try I cannot override it.</p>
  
  <p>I have tried late static binding, getting/setting variables statically using a container class but no matter what I try the parent is always rendered with the original "Set from slim" variable value. I have pin pointed this down to the fact that $context is not passed by reference around twig.</p>
  
  <p>Surely someone in the past has hit this wall before and knows a work around?</p>
  
  <p>Please help!</p>
  
  <p>Thanks in advance</p>
  
  <p>EDIT:</p>
  
  <p>The suggested answer does not answer the question. It attemps to defer rendering from inside the template file, I wish to override variables from a different file at runtime.</p>