Skip to main content
added 34 characters in body
Source Link
Brad Bell
  • 67.6k
  • 6
  • 75
  • 145

Getting error:

Calling unknown method: craft\web\twig\variables\CraftVariable::markAsReadModule()

Trying to use a template variable that I created in my craft cmsCraft 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.phpcraft/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.phpcraft/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.phpcraft/modules/markasreadmodule/MarkAsReadModule.php

Getting error:

Calling unknown method: craft\web\twig\variables\CraftVariable::markAsReadModule()

Trying to use a template variable that I created in my craft cms 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

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

Source Link
Brad
  • 487
  • 3
  • 11

Incorrectly setting module template variable

Getting error:

Calling unknown method: craft\web\twig\variables\CraftVariable::markAsReadModule()

Trying to use a template variable that I created in my craft cms 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