0

In my custom Twig tag I am trying to reference a class in the Twig_Node compile method, however I receive an error every time stating it can't find it. What would the path be to a custom plugin class for the Twig_Node?

Fatal error: Class 'PluginCustomClass' not found in /Volumes/Grid/Devbox/www/event.craft.dev/craft/app/vendor/twig/twig/lib/Twig/Environment.php(403) : eval()'d code on line 431

public function compile(\Twig_Compiler $compiler)
    {
        $compiler
            ->addDebugInfo($this)
            ->subcompile($this->getNode('pluginTarget'))
            ->raw(', ')
            ->subcompile($this->getNode('elementsTarget'))
            ->raw(') = new \PluginCustomClass(')
            ->subcompile($this->getNode('criteria'))
            ->raw(");\n");
    }
2

Assuming PluginCustomClass is a class inside of a Craft plugin, then the issue is probably that you need to reference it in the Craft namespace. Something like this should work:

->raw(') = new \Craft\PluginCustomClass(')

Depending on what type of class that is (Service, Variable, Helper, standalone, etc.), Craft might not have auto-loaded it, so you might need to manually require it as well.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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