Table of Contents

  1. Horde_View
    1. Example usage
    2. Base functionality
    3. Helper functionality
      1. Benchmark
      2. Capture
      3. Debug
      4. Form Tag
      5. Form
      6. Javascript
      7. Number
      8. Tag
      9. Text
      10. Url
    4. Helpers
      1. Overview
      2. Example
      3. Organization


Documentation on the Horde_View package. This documentation is adopted from the MAD documentation (, as many of the Horde View ideas are also adopted from MAD, and the helpers are directly compatible between the two systems.

The following explanations correspond to Horde 5.

Example usage

Calling code


require_once __DIR__ . '/lib/Application.php';

// use a model to get the data for book authors and titles.
$data = array(
        'author' => 'Hernando de Soto',
        'title' => 'The Mystery of Capitalism'
        'author' => 'Henry Hazlitt',
        'title' => 'Economics in One Lesson'
        'author' => 'Milton Friedman',
        'title' => 'Free to Choose'

$view = new Horde_View (array('templatePath' => 'viewtest'));
$view->books = $data;

// and render a template called "template.php"
echo $view->render('template.php');

View template

Put the following code into viewtest/template.php (the template path is set above):

<?php if ($this->books): ?>

<!-- A table of some books. -->

<?php foreach ($this->books as $key => $val): ?>
        <td><?php echo $this->escape($val['author']) ?></td>
        <td><?php echo $this->escape($val['title']) ?></td>
<?php endforeach ?>


<?php else: ?>

    <p>There are no books to display.</p>

<?php endif ?>

Base functionality

Helper functionality




Form Tag









Views separate the presentation from the controllers and models. Views are allowed to have logic, provided that the logic is only for presentation purposes. This presentation logic is small bits of PHP code embedded in the HTML.

Bits of presentation logic code can be extracted into helper methods. Once extracted, a helper method can be called in the view in place of the former code block. Extracting presentation logic into helpers is a best practice and helps keep views clean and DRY.

Helpers are simply methods of a class. The framework mixes the helpers into the view behind the scenes, and makes them appear as methods inside the view. An example of a helper class with a single highlight() helper follows. For more detailed information, refer to


In the above example template, a function of Horde_View_Helper_Tag is used. Functions can be overloaded and additional helpers can be defined. For instance, you might whish to highlight a certain name in your booklist. You could define a corresponding function and put it into your own helper class in file yourapp/lib/Helper.php:

class Yourapp_Helper extends Horde_View_Helper_Base
     * Highlights a phrase within the given text.
     * @param string $text
     * @param string $phrase
     * @return string
    public function highlight($text, $phrase)
        if (empty($phrase) || empty($text)) {
            return $text;
        $highlighter = '<strong class="highlight">' . $this->escape($phrase) . '</strong>';
        return preg_replace('/' . preg_quote($phrase) . '/', $highlighter, $text); 

To use this helper, it helper must be added to the view you are using (w/ref. to above view.php):


And in template.php:

       <td><?php echo $this->highlight($val['author'], 'Soto') ?></td>

It is OK to put HTML into helper class methods because they exist to assist with presentation. However, it is NOT OK to put print/echo statements within a helper class. Helper methods always return a value that is displayed in the view like <?= $this->highlight($text) ?>.


As shown above, helpers are methods that are organized into classes. The framework will mix helper methods together through overloading. Inside a view, helper methods from all of the sources above can be called by simply using <?= $this->helperMethod() ?>.