<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="learning.layout.intro">
    <title>Introduction</title>

    <para>
        When building a website using Zend Framework <acronym>MVC</acronym> layers, your view
        scripts will typically be just snippets of <acronym>HTML</acronym> pertinent to the
        requested action. For instance, if you had the action "<filename>/user/list</filename>",
        you might create a view script that iterates through the users and presents an unordered
        list:
    </para>

    <programlisting language="php"><![CDATA[
<h2>Users</h2>
<ul>
    <?php if (!count($this->users)): ?>
    <li>No users found</li>
    <?php else: ?>
    <?php foreach ($this->users as $user): ?>
    <li>
        <?php echo $this->escape($user->fullname) ?>
        (<?php echo $this->escape($user->email) ?>)
    </li>
    <?php endforeach ?>
    <?php endif ?>
</ul>
]]></programlisting>

    <para>
        Since this is just a snippet of <acronym>HTML</acronym>, it's not a valid page; it's missing
        a <acronym>DOCTYPE</acronym> declaration, and the opening <acronym>HTML</acronym> and
        <acronym>BODY</acronym> tags. So, the question is, where will these be created?
    </para>

    <para>
        In early versions of Zend Framework, developers often created "header" and "footer" view
        scripts that had these artifacts, and then in each view script they would render them. While
        this methodology worked, it also made it difficult to refactor later, or to build composite
        content by calling multiple actions.
    </para>

    <para>
        The <ulink url="http://martinfowler.com/eaaCatalog/twoStepView.html">Two Step View</ulink>
        design pattern answers many of the issues presented. In this pattern, the "application" view
        is created first, and then injected into the "page" view, which is then presented to the
        client. The page view can be thought of as your site-wide template or layout, and would have
        common elements used across various pages.
    </para>

    <para>
        Within Zend Framework, <classname>Zend_Layout</classname> implements the Two Step View
        pattern.
    </para>
</sect1>
