Creating Custom Blocks

 
Apr

26

2012

Creating Custom Blocks

2012-04-26 12:02:43 & Posted by : Mr Super admin root

A block is a dynamic data model. The purpose of a block is to replace the static view model of MVC application by using a model that can be updated at run time—that is, by using a dynamic block.

In short blocks are dynamic data models that use block templates to make the data visible to the user in the way you want. 
Block templates are fragments of markup for rendering shapes. Examples of shapes include menus, menu items, newsletter, quick contact, mini login, and messages.
 
In the Zend framework the block is a Partial view helper is used to render a specified template within its own variable scope. The primary use is for reusable template fragments with which you do not need to worry about variable name clashes. Additionally, they allow you to specify partial view scripts from specific modules.
 
A sibling to the Partial, the PartialLoop view helper allows you to pass iterable data, and render a partial for each item. Click Here to know more about Zend Partial view helper.

Basic Usage of Partials by Zend Framework Docs
 

Basic usage of partials is to render a template fragment in its own view scope. Consider the following partial script:

  1. <?php // partial.phtml ?>
  2. <ul>
  3.     <li>From: <?php echo $this->escape($this->from) ?></li>
  4.     <li>Subject: <?php echo $this->escape($this->subject) ?></li>
  5. </ul>

You would then call it from your view script using the following:

  1. <?php echo $this->partial('partial.phtml'array(
  2.     'from' => 'Team Framework',
  3.     'subject' => 'view partials'))?>

Which would then render:

  1. <ul>
  2.     <li>From: Team Framework</li>
  3.     <li>Subject: view partials</li>
  4. </ul>

Top