Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
View or Theme?
  • 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.

    Thanks!
  • As always, the answer is "it depends".

    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.
  • Yeah, it is exactly what I thought.
    It seems that using Theme is better than View, an application is more reusable and can be mantained with less effort.

    I think I'll do that:
    1) Release the "module" folder, so every BE functionality will be there
    2) Release the module "theme" folder, so every one can create its own theme based on mine.

    Should it be an acceptable solution to release a module?
    I'm new in this kind of stuff and I want to start doing it in the "right way".
  • HarroHarro
    Accepted Answer
    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.
  • Yes, I think I will follow this style, I think it is the best one to share a module.
    I'll try :-]

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion