Creating Custom Blocks




Creating Custom Blocks

2012-04-26 12:02:43 & Posted by : Mr Developer Developer

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.  // partial.phtml ?>
  3. From:  echo $this->escape($this->from) ?>
  • Subject:  echo $this->escape($this->subject) ?>
  • You would then call it from your view script using the following:

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

    Which would then render:

    2. From: Team Framework
  • Subject: view partials

  • Comments

    Add a Comment