How to use the partial view helper in Zend Framework 2.5

In the Zend Framework you can use the partial view helper is used to render a template fragment in its own view scope.

You can easily save a template fragment as a new phtml file in your view folder. And, to call, it, you can use the helper partial or PartialLoop.

I have used the partial view helper in my new open source script to render the top of page:

<nav class="navbar navbar-default navbar-static-top">
<div class="container-fluid">
<div class="container">
<ul class="nav navbar-nav navbar-left">
<li><i class="fa fa-phone-square"></i> <?php echo $this->escapeHtml($this->phone) ?></li>
<li><i class="fa fa-envelope"></i> <?php echo $this->escapeHtml($this->email) ?></li>

<ul class="nav navbar-nav navbar-right">
<li class="dropdown ">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
<i class="fa fa-user"></i> My account
<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li class=""><a href="#">Login</a>
<li class=""><a href="#">Register</a>

To call this fragment, I have used this code:

<?php echo $this->partial('top.phtml', array(
'phone' => '1 (800) 000-0000',
'email' => '')); ?>

Video tutorial:

Leave a Comment