Before I go into detail and share my error logs and plugin details, I'll ask the simple question first:

When testing my 404 page, no plugin functionality works. Is this intentional?

Just for testing purposes, I tried to include the index template file in my 404 template:

{% include 'index' %}

This pulls in the homepage fine, but still causes an error:

Variable "pluginName" does not exist in "404"...

The following returns 'yes' when legitmately on the homepage, and 'no' when on a 404 page, which uses the include I just mentioned.

{{ pluginName is defined ? 'yes' : 'no'}}

Any insight would be great.


  • There should not be any difference and your plugin / plugin variables should work on 404 just like on any other template. Does Twig / Craft work at all?
    – carlcs
    Commented Oct 6, 2015 at 7:06
  • That's the weird thing. Craft/Twig functions work perfectly. {{ craft.request.getLastSegment() }} for example is fine. I'm going to give my plugin the once-over to see if there are any obvious issues. Commented Oct 6, 2015 at 8:21

2 Answers 2


Ok, this is what I get for trying to be clever (lazy)...

I've always begrudged typing in 'craft.myPlugin...' every time I wanted refer to my plugin, so I set a Route Variable in my plugin like so:

      'myPlugin' => craft()->myPlugin, 

It would appear none of my route variables work in the 404 template. That in itself is a bit odd, so to accomodate my laziness I've added this to the top of my 404 code:

{% set myPlugin = craft.myPlugin %}

It would be interesting to know if this choice has any detrimental effects? (besides being looked down upon by my peers)


If you want to make a new variable available globally, you should do it by registering a new Twig extension, using the addTwigExtension hook. You can use the Twig extension’s getGlobals() method to create whatever new global variables you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.