lindquist Posted March 13, 2015 Share Posted March 13, 2015 Hi, I'm working on a calendar module for a site. I have a Process module that provides an admin page, which using fullcalendar, wraps up the creating of event pages a bit so it's doable for the client. Right now, I have the logic to provide a JSON feed of events in the Process module, and essentially the same logic in the templates to generate the event listing. I'm not interested in using fullcalender in the frontend for this site, so while the event are obviously the same, the Process module needs to generate a JSON event list, while the frontend template just needs to iterate the events and render them as it pleases. I'd like to generalize my code a bit, so that both the Process module and the frontend template can use the same code to generate the events, then just output them differently. That includes stuff like expanding recurrences - which right now is pretty much duplicated. I'm thinking it would be nice to have a $calendar variable in the templates, and I guess that would/could end up as a $this->wire('calendar') in the Process module, but I'm quite new to ProcessWire development (I've done a few sites where only clicking around in Admin and writing templates was necessary), so a few pointer on how to go about this and/or where to look would be greatly appreciated. I hope it makes sense Thanks in advance Link to comment Share on other sites More sharing options...
lindquist Posted March 13, 2015 Author Share Posted March 13, 2015 I made a simple Module holding my logic, made my Process module dependent on it, and access it as wire('modules')->getModule('Calendar') it does the job 3 Link to comment Share on other sites More sharing options...
Wanze Posted March 13, 2015 Share Posted March 13, 2015 Hi lindquist, That's a good solution you've come up with. If you want to provide an API variable for your object, here's an example, pretty easy like everything in ProcessWire: // This must be inside an autoload module public function ready() { $this->wire('calendar', new Calendar()); } // Or, if you're Calendar module is autoloaded, make the same instance available as API variable public function ready() { $this->wire('calendar', $this); } 4 Link to comment Share on other sites More sharing options...
lindquist Posted March 13, 2015 Author Share Posted March 13, 2015 Thanks Wanze I think I might as well not make the module autoload, since it's only needed on a specific calendar page. So getModule will be fine 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