views:

31

answers:

1

Hi

I have a layout which works fine. This layout contains several partials, which display adverts, a side column a slideshow, etc. All of these are likely to change depending on which page (module/controller/action) of the site you are on.

What is the best way of doing this correctly? In the past I have assigned variables to my view inside my controllers, these are then passed to the partial which then displays the correct slideshow or advert. This seems ugly and not entirely correct for an MVC application.

Does anyone have any other methods of doing this?

+1  A: 

Partials are just another view scripts.

My advice is: newer put your logic into the view scripts. Your may store the logic in:

  • models (remember, that you can create your own models, extending, or not extending the basic database models, eg. data hydrators)
  • view helpers (with parameters)
  • services (dependent on models, returning models)
  • combination of the above

Then use view helper or pass the ready data (model) to different partials.

Tip: Dependency injection is a good thing.

takeshin
All good points. View Helpers sounds like the best best for me at the moment
jakenoble