Add / Update context from macro I'm trying to update the context from within a macro. Is this possible at all? I'm pretty close with the below code.

The var_dump within the below function shows the updated context. But when doing a {{ dump(_context|keys) }} after the macro call the context is unchanged.

Any ideas, much appreciated.

&lt;?php
namespace Craft;

class TwiggedTwigExtension extends \Twig_Extension
{
  public function getName()
  {
    return 'Twigged';
  }

  public function getFunctions()
  {
    return array(
      'addVar' =&gt; new \Twig_SimpleFunction('addVar', array($this, 'addVar'), array('needs_context' =&gt; true)),
    );
  }

  public function addVar($context, $str, $val)
  {
    $context['context'][$str] = $val;
    var_dump(array_keys($context['context']));
  }
}
So I took another approach to my problem and ended up creating a plugin variable allowing me to set data inside a macro and have it accessible in the template. It's not complicated and does the trick.

class MyPluginVariable
{
  /**
   * Store data for use within both
   * templates and macros. Easy way around
   * macros having their own context
   * @var [Array]
   */
  private static $store = [];

  /**
   * Set data in storage array
   * @param [String] $key
   * @param $value
   */
  public function set($key, $value) {
    self::$store[$key] = $value;
  }

  /**
   * Retrieve data from storage array
   * @param  [String] $key
   */
  public function get($key) {
    return self::$store[$key];
  }
}


To set data you simply call {% do craft.MyPlugin.set('myVar', true) %} and to retrieve it {% set myVar = craft.MyPlugin.get('myVar') %}