neonwired Posted December 6, 2016 Share Posted December 6, 2016 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 More sharing options...
owzim Posted December 6, 2016 Share Posted December 6, 2016 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'); 3 Link to comment Share on other sites More sharing options...
neonwired Posted December 7, 2016 Author Share Posted December 7, 2016 It was extending WireData but i'd forgotten to add namespace ProcessWire; Thanks for your help. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now