1

In my Craft 3 plugin I would like to pass a variable defined in my Controller to my PluginVariable.php file. Is this possible?

  • 1
    Maybe you should improve your question with at least one example of what you'd like to achieve. When building a plugin, I couldn't think of a use case where passing a variable from a controller to the plugin variable would be a good idea. – Paul Nov 23 '18 at 14:57
2

The shortest answer is "that's not possible," and the slightly longer answer is "that's not possible because Controllers and Variables have no reason to ever interact." If your Controller relies on a Variable (or vice versa), something is architecturally incorrect. There's no reason for the two to cross paths.

The purpose of a Controller is to receive input from a form, AJAX call, or to be used as an API endpoint. It can also be used via routing to show a particular template under particular conditions.

The purpose of a Variable is simply to render a value in your Twig template.

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.