Hi guys, I have some trouble about using View or Theme. I know how to use a View and how to use a Theme, my problem is about a module I want to release.
Is it better to release a module that use Views or a module that use Theme?
My problem is about nested view:
- a controller uses view (for example, the "action_create" method has the view "create")
- the "create" view needs another view named "form"
- I need to pass some data to the form view
How can you do that with Views? Because with a Theme I have a unique instance where I can sto re come data and use it everywhere in my project.
Views are stored in the views folder of the module, and therefore tied to that module. If you want to re-use the module in a different application with a completely different layout, it could be that your views can not be used. In short, views limit module portability.
If you use themes, the module views are outside the module folder, making it easier to port the module to other applications, while still maintaining a single codebase. You maintain the theme of that application separately (together with the app itself).
If you want to use views as templates, you need to construct the individual "sub" views, and pass them all back to the controller action so they can be added to the template view. There are no separate instances, the View system isn't designed to create instances, a View is only an object encapsulation of a view file.
The theme class should fall back to the views folder if the requested view can not be found in the active or fallback theme.
So perhaps you could provide a set of default views with basic styling in the module itself, which can be copied to the theme of the receiving application for customisation.
I haven't tried it yet, so I don't know exactly what folder structure the module would need to support this.