I have a plugin with nothing but the following in the init() method other than the basics (just for testing purposes):
craft()->urlManager->setRouteVariables(array(
'foo' => array('bar' => 'baz')
));
From all of my routes I can access this just fine. It's working for static templates, dynamic entries, etc. To access it I'm using the following code in my main base template /_layouts/base.twig
:
{{ foo.bar }}
The output is as expected: baz
However, I cannot access this from a page that does not exist, i.e., a 404. If I go to my-site.com/doesnt-exist
I receive the following:
Twig_Error_Runtime
Variable "foo" does not exist in "_layouts/base" at line 1
My 404 template is extending base as well.
What am I doing wrong?
It's probably worth noting that the reason I'm trying to do this is because I want to include a form on the 404 page (that I also include in other areas, so it's setup as a partial) and I'm having trouble passing error validation back and forth with setRouteVariables
, but only for 404 pages. I know I could do this with a session and that is my current work around, but I wanted to see if there was a better way.