Renderpartial Vs Include

Is there any benefit of using renderPartial as opposed to a standard PHP include when inserting common code snippets?

as minimum: you can pass a variables to rendered view. And this looks better than include.

for example:


$variable_for_included_file = 'value';

include "template.php";

too hard to understand a $variable_for_included_file will be using into template.php or below at current file.

but this, as I think looks better:


$this->renderPartial('template', array('variable'=>'value'));

Sorry for my English. It’s very hard for me :(

True, but that also means we have to pass in every variable that is already in the parent file. Using include(), all the variables are already available.

Yes. And those variables that do not intended for include file.

If you worry about performance then yes this is not so faster as include. But all “OOP-part” slower than procedures :)

renderPartial() is not equal to include(). For example, it supports theming and allows to include registered css & js.