Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (3)

View Page History
Partials implement the Composite View Pattern defined in J2EE Design Patterns. Although template fragment rendering is likely the majority use case, partials are infinitely nestable and can thus compose a nested tree of Zend_View objects for above average complex Views.

Since the primary use case of partials is for use in loops, an additional helper, partialLoop, will be created. This will take the passed array and loop over it, passing each element to the partial view script requested.

*./src/default/views/scripts/blog/index.phtml*
{code:php}
{code}

*./src/default/views/scripts/blog/index_alt.phtml*
{code:php}
<?php echo $this->render('stdHeader.phtml') ?>

<div class="blog content">
<?php /* same thing as above, but instead of putting loop in view
* script, handled in the helper
*/ ?>
<?php echo $this->partialLoop('_entry.phtml', $this->entries) ?>
</div>

<?php echo $this->render('stdFooter.phtml') ?>
{code}

||UC-02||

{code}

*Zend_View_Helper_PartialLoop*
{code:php}
/**
* Helper for rendering a template fragment in its own variable scope, looping
* over an array.
*
* @package Zend_View
* @subpackage Helpers
* @copyright Copyright (c) 2007 Pádraic Brady (http://blog.astrumfutura.com)
* @license New BSD
*/
class Zend_View_Helper_PartialLoop extends Zend_View_Helper_Partial {

/**
* Renders a template fragment within a variable scope distinct from the
* calling View object.
*
* @param string $name
* @param string|array $module
* @param array $model
* @returns string $output
*/
public function partialLoop($name, $module = null, array $model = null)
{
if ((null === $model) && is_array($module)) {
$model = $module;
}
if (null === $model) {
return '';
}

$content = '';
foreach ($model as $item) {
$content .= $this->partial($name, $module, $model);
}

return $content;
}
}
{code}

*Zend_View_Helper_Controller*
{code:php}