I am having a difficult time understanding how to output even a simple variable using a module. Ultimately I have PHP code that I need to execute to generate a PDF. I managed to do this in V2.5. I'm following all the tutorials that I can find, bu none I feel aren't clear. Any recommendations on the simplest of examples, even if it's just outputting a variable.


2 Answers 2


I haven't tried this tutorial yet, but having learned a lot about Craft 3 from Andrew Welch's other tutorials, I don't doubt this may have some nuggets of useful information to get you on your way.


  • 1
    Thanks, I did see this and went through it several times, but it didn't explain how to output data into template. It's for adding a background to the login screen, just not what I need. Thank you though. Commented Aug 21, 2018 at 15:52
  • 1
    To output something into a template, you'd want to create either a Variable or a Twig Extension, just as you would for a plugin. There's a tutorial here as well: craftquest.io/livestreams/building-a-craft-module Commented Aug 21, 2018 at 19:00

These are the pieces I needed to complete the puzzle:

  • Docs for Craft controllers
  • Docs for Yii controllers
  • Create a FooController class in your module
  • Add a actionBar() method in that class
  • Make sure the $this->controllerNamespace in your module init is correct
  • Now, assuming your module is registered as baz-module in config/app.php then you can reach your controller with a form like
    <form method="post">
        {{ csrfInput() }}
        {{ actionInput('baz-module/foo/bar') }}

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.