<p>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.</p>

<p><a href="https://nystudio107.com/blog/enhancing-a-craft-cms-3-website-with-a-custom-module" rel="nofollow noreferrer">https://nystudio107.com/blog/enhancing-a-craft-cms-3-website-with-a-custom-module</a></p>

CC BY-SA 4.0
2018-08-21T15:52:38.143Z
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
CC BY-SA 4.0
2018-08-21T19:00:48.217Z
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
CC BY-SA 4.0
2018-08-21T14:55:42.660Z
2018-08-21T14:55:42.660Z
Jay
<p>These are the pieces I needed to complete the puzzle:</p>
<ul>
<li>Docs for <a href="https://craftcms.com/docs/3.x/extend/controllers.html" rel="nofollow noreferrer">Craft controllers</a></li>
<li>Docs for <a href="https://www.yiiframework.com/doc/guide/2.0/en/structure-controllers" rel="nofollow noreferrer">Yii controllers</a></li>
<li>Create a <code>FooController</code> class in your module</li>
<li>Add a <code>actionBar()</code> method in that class</li>
<li>Make sure the <code>$this-&gt;controllerNamespace</code> in your module <code>init</code> is correct</li>
<li>Now, assuming your module is registered as <code>baz-module</code> in <code>config/app.php</code> then you can reach your controller with a form like</li>
</ul>
<pre class="lang-twig prettyprint-override"><code>    &lt;form method=&quot;post&quot;&gt;
        {{ csrfInput() }}
        {{ actionInput('baz-module/foo/bar') }}
        &lt;button&gt;Submit&lt;/button&gt;
    &lt;/form&gt;
</code></pre>

CC BY-SA 4.0
2021-03-11T10:29:32.137Z
2021-03-11T10:29:32.137Z
Tamlyn
<p>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.</p>

<p>Thanks</p>

<modules>
Basic Module Tutorial or Example
# Basic Module Tutorial or Example

(Asked by: username_0 on 2018-08-21)

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

**Tags:** modules


---

## 2 answers

### Answer by username_1 on 2018-08-21. Score: 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>

> **Comments:**
> **username_0**: 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.  
> **username_2**: 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  

---

### Answer by username_3 on 2021-03-11. Score: 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

    
        {{ csrfInput() }}
        {{ actionInput('baz-module/foo/bar') }}
        Submit


---

