Is it possible to access Twig variables in a plugin variable using PHP? I have a controller that returns route variables to the page:

craft()-&gt;urlManager-&gt;setRouteVariables(array(
  'errors' =&gt; $entry-&gt;getErrors()
));


On the page that gets loaded, I can access the variables I set in the template:

{% for error in errors %} ...


However, I want to handle this variable dynamically. Is it possible to access the 'errors' variable in my MyPluginVariable.php file without passing it directly to my variable function? 

I don't want to do this:

{{ craft.myPlugin.doSomething(errors) }}


That passes my variable to the plugin variable and I can access it just fine.  But I don't want to ask the user to pass this variable to the function every time, I'd prefer to just handle it in the background.

So, on the page that gets loaded, instead of outputting the variable, can I have a Twig tag like this:

{{ craft.myPlugin.doSomething() }}


And directly access the 'errors' variable in my plugin?  Something like (this doesn't work):

craft()-&gt;request-&gt;getRouteVariables('errors')
You can’t access the current Twig variables (the “context”, as Twig calls them), from a Template Variable class, but you can access them with a template hook.

From your plugin’s init() function:

craft()-&gt;templates-&gt;hook('errorCheck', function(&amp;$context)
{
    if (isset($context['errors']))
    {
        // do something with $context['errors'];
    }
});


From your template:

{% hook "errorCheck" %}


You can modify, delete, and create variables within that $context array if you want. And because it is passed by reference (that’s what the “&amp;” does in “&amp;$context”, you won’t need to actually return the array at the end of the function or anything; just make your changes to it.