3

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.

Thanks

2 Answers2

4

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.

https://nystudio107.com/blog/enhancing-a-craft-cms-3-website-with-a-custom-module

Jay
  • 1,042
  • 7
  • 24
  • 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. – Danny Valle Aug 21 '18 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: https://craftquest.io/livestreams/building-a-craft-module – andrew.welch Aug 21 '18 at 19:00
3

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') }}
        <button>Submit</button>
    </form>
Tamlyn
  • 183
  • 6