Reputation: 31719
why should i use a component instead of an action that renders a partial?
If actions can render partials, when is better using components?
Give me light about it..
Javi
Upvotes: 5
Views: 6235
Reputation: 11202
partial is a 'template' that can be reused in any view pages. its simple & fast. all $data must be passed as parameter to the partial. imo, should be preferred if possible.
component is like a 'template with its own action' that can be reused in any view pages. more powerful, but slower compared to partial. use if you have partials that require business logic (i.e. action/controller)
http://www.symfony-project.org/book/1_0/07-Inside-the-View-Layer#chapter_07_code_fragments
Upvotes: 5
Reputation: 8695
components are used when you want to include some kind of block in different parts of the site (for example, a "Top 10 Sales" or something similar) - that requires some controller code to render. You include a component's output in another template of an action / partial / another component by using
include_component($module_name, $component_name, array('var1' => $var1));an action is supposed to be called directly by the browser , so you can't include it's output in another template (without some kind of hack) Think of components as a reusable block of html that can get included anywhere, vs actions that are the whole page rendered and sent to the browser
Upvotes: 7