Jump to content

Make a module available to a template


neonwired
 Share

Recommended Posts

I'm trying to write my first module and am a bit confused about how to make a variable available to templates.

I've seen both of these in the init function and neither seem to work for me.

wire("fuel")->set("html", $this);

$this->wire->set("html", $this);

$html is always NULL in my template.

Which is correct or are both wrong?

 

Link to comment
Share on other sites

If your module extends Wire or any Wire derived class, you should be able to this in your init() method.

public function init()
{
    $this->wire('html', $this);
}

Are you sure the module is loaded when the template is rendered? See the autoload option in your modules config:

public static function getModuleInfo()
{
    return array(
        'title'    => 'Example module',
        'version'  => '1.0.0',
        'singular' => true,
        'autoload' => true,
    );
}

You could also load it manually:

$html = $modules->get('ModuleName');

 

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...