Answers.Body: <p>Was running into the same problem today. I was able to access the controller and the service, but none of the variables. Looks like Brad was able to fix the problem but didn't add a final solution. </p>
  
  <p>I wasn't registering any variables on the <code>init()</code> function. Adding the last line of code registered the variable but did not load it onto every request. </p>
  
  <pre><code>    // Register our variables
      Event::on(
          CraftVariable::class,
          CraftVariable::EVENT_INIT,
          function (Event $event) {
              /** @var CraftVariable $variable */
              $variable = $event-&gt;sender;
              $variable-&gt;set('formSenderModule', FormSenderModuleVariable::class);
          }
      );
  </code></pre>
  
  <p>To add it onto every request, I had to add <code>form-sender-module</code> into my bootstrap array in <code>app.php</code>. </p>
  
  <pre><code>'bootstrap' =&gt; ['form-sender-module']
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-11T11:30:14.227Z
Answers.LastActivityDate: 2020-02-11T11:30:14.227Z
Answers.UserDisplayName: Jamie Hunt
Body: <p>Getting error: </p>
  
  <blockquote>
    <p>Calling unknown method:
    craft\web\twig\variables\CraftVariable::markAsReadModule()</p>
  </blockquote>
  
  <p>Trying to use a template variable that I created in my Craft 3 module, I use this module for other things that work as expected but I am running into an issue with this in the template:</p>
  
  <pre><code>{{ craft.markAsReadModule.read(entry.id) }}
  </code></pre>
  
  <p>In the init method for <code>craft/modules/markasreadmodule/MarkAsReadModule.php</code> I register the variable:</p>
  
  <p>I am using:</p>
  
  <pre><code>use craft\web\twig\variables\CraftVariable;
  use modules\markasreadmodule\variables\MarkAsReadModuleVariable;
  </code></pre>
  
  <p>Then I have this in the init:</p>
  
  <pre><code>Event::on(
      CraftVariable::class,
      CraftVariable::EVENT_INIT,
      function (Event $event) {
          /** @var CraftVariable $variable */
          $variable = $event-&gt;sender;
          $variable-&gt;set('markAsReadModule', MarkAsReadModuleVariable::class);
      }
  );
  </code></pre>
  
  <p>In <code>craft/modules/markasreadmodule/variables/MarkAsReadModuleVariable.php</code></p>
  
  <pre><code>public function read($entryId)
  {
      $service = new MarkAsRead(); // initialize the service class
      $read = $service-&gt;read($entryId);
  }
  </code></pre>
  
  <p>I suspect I am setting the naming convention where I include it in the template and/or in the init method within <code>craft/modules/markasreadmodule/MarkAsReadModule.php</code></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-01-08T20:08:01.030Z
Comments.Text: Not seeing anything obviously wrong... are you sure your module is being bootstrapped/loaded?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-01-08T20:51:54.530Z
Comments.Text: I goofed on the bootstrap array in the app.php config, thanks.
Comments.UserDisplayName: Brad
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-01-08T21:25:20.560Z
Comments.Text: Glad you're sorted... would you mind adding your solution as an official answer? Might end up helping someone in the future.
Comments.UserDisplayName: Brad Bell
Tags: <templating><craft3><variable><modules>
Title: Incorrectly setting module template variable
ThreadText: # Incorrectly setting module template variable
  
  (Asked by: username_0 on 2019-01-08)
  
  Getting error:
  
  > Calling unknown method:
  > craft\web\twig\variables\CraftVariable::markAsReadModule()
  
  Trying to use a template variable that I created in my Craft 3 module, I use this module for other things that work as expected but I am running into an issue with this in the template:
  
  ```
  {{ craft.markAsReadModule.read(entry.id) }}
  
  ```
  
  In the init method for `craft/modules/markasreadmodule/MarkAsReadModule.php` I register the variable:
  
  I am using:
  
  ```
  use craft\web\twig\variables\CraftVariable;
  use modules\markasreadmodule\variables\MarkAsReadModuleVariable;
  
  ```
  
  Then I have this in the init:
  
  ```
  Event::on(
      CraftVariable::class,
      CraftVariable::EVENT_INIT,
      function (Event $event) {
          /** @var CraftVariable $variable */
          $variable = $event->sender;
          $variable->set('markAsReadModule', MarkAsReadModuleVariable::class);
      }
  );
  
  ```
  
  In `craft/modules/markasreadmodule/variables/MarkAsReadModuleVariable.php`
  
  ```
  public function read($entryId)
  {
      $service = new MarkAsRead(); // initialize the service class
      $read = $service->read($entryId);
  }
  
  ```
  
  I suspect I am setting the naming convention where I include it in the template and/or in the init method within `craft/modules/markasreadmodule/MarkAsReadModule.php`
  
  **Tags:** templating, craft3, variable, modules
  
  > **Comments:**
  > **username_1**: Not seeing anything obviously wrong... are you sure your module is being bootstrapped/loaded?  
  > **username_0**: I goofed on the bootstrap array in the app.php config, thanks.  
  > **username_1**: Glad you're sorted... would you mind adding your solution as an official answer? Might end up helping someone in the future.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-02-11. Score: 2
  
  Was running into the same problem today. I was able to access the controller and the service, but none of the variables. Looks like username_0 was able to fix the problem but didn't add a final solution.
  
  I wasn't registering any variables on the `init()` function. Adding the last line of code registered the variable but did not load it onto every request.
  
  ```
      // Register our variables
      Event::on(
          CraftVariable::class,
          CraftVariable::EVENT_INIT,
          function (Event $event) {
              /** @var CraftVariable $variable */
              $variable = $event->sender;
              $variable->set('formSenderModule', FormSenderModuleVariable::class);
          }
      );
  
  ```
  
  To add it onto every request, I had to add `form-sender-module` into my bootstrap array in `app.php`.
  
  ```
  'bootstrap' => ['form-sender-module']
  
  ```
  
  
  ---
  
  