How do I... Put a module as a view/element into a template and/or into a page/view
What I need to do is be able to statically and dynamically present a module's controller methods as a view (read HTML), and display those views within other views, blocks and/or page content. I recently switched over to fuel, because it really looks like you guys know what you are doing, and have tackled alot of the problems I have encountered in the past.
I have been able to easily create this sort of functionality with my own stack of CI extensions (Ie. not using fuel). I've done this using HMVC, and DataMapper for ORM. What I'd like to know is how I can make this work using fuel, if I create a simple and/or advanced module.
As an example.... If I decided to have a News module, and a "get_top_3" method in a news controller within that module, that returns a list of the top 3 news items (in HTML), how would I be able to place that "view" within a layout and/or block element in fuel CMS?
Thanks ahead of time for looking at this.
Comments
$this->fuel->pages->render('mypage', $vars);
http://docs.getfuelcms.com/general/pages-variables
For blocks, which are essentially partials and stored in the _views/_blocks folder, you can use the "fuel_block('my_view')" function. The added benefit of using fuel_block instead of the load->view method is that it will also check the CMS for a block with the same name and serve that up instead (assuming your fuel_mode in MY_fuel.php is set to "auto").
With regards to "module" methods, I'm guessing you are meaning a model method that's associated with your module. Simple modules are essentially just wrappers around a model.
For what you are explaining, we usually take the controller out of the equation and add the model::get_top_3 call at the top of a block or view file to keep things together.
I realize this may not answer your question entirely, so please follow up with any more additional information you think may help.
Thanks for the reply
We are currently trying to create a front-facing (client-side) survey module for fuel. Currently, we have used a "simple" module, which as you have stated is just a MY_Model that has been extended with base_module_model functionality.
Creating the surveys on the back-end (admin) is ridiculously easy (Thank you!) because it is a simple module. Let's pretend that the administrator can create a survey, with up to 3 questions, and because this is a simple module, there is a corresponding table on the database that relates to this. We would then like this module to show up, wherever we want. Ie. I would like to place it in the main layout, so that it shows up in every page that uses that layout. There could be other instances as well, where I may want to place the survey such as: CMS page, normal view file, a block view, other layouts, etc.
When I say I would like it to "show up" what I mean is I would like to display a view, that is generated (most likely by a controller, using Form Builder) that allows any site visitor to vote for the current survey, which will update the database and increment the corresponding answers total.
I should throw out a disclaimer right now I do have this working, but not in the way intended. I have created a controller (controllers/survey) that does use Form Builder, creates a form that displays a list of options derived from a survey record and presents it in a view file. The problem is how I display it on the page. Currently, in order to include it in the main layout page, I am AJAX loading it from a view block (_blocks/survey). In the block lives the JS code that loads the view from the controller. However, like I had stated: Not what I intend. This relies on the client having javascript enabled, and also means that any content loaded will not be indexed by search engines. There are even more reasons not to use this method, but I am still not understanding how else I can load a module (or controller) function, as a view into another view file, while still keeping an MVC approach. Please help!