<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.yaf-view-simple.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'yaf-view-simple.render.php',
    1 => 'Yaf_View_Simple::render',
    2 => 'Render a template',
  ),
  'up' => 
  array (
    0 => 'class.yaf-view-simple.php',
    1 => 'Yaf_View_Simple',
  ),
  'prev' => 
  array (
    0 => 'yaf-view-simple.isset.php',
    1 => 'Yaf_View_Simple::__isset',
  ),
  'next' => 
  array (
    0 => 'yaf-view-simple.set.php',
    1 => 'Yaf_View_Simple::__set',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/yaf/yaf_view_simple/render.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="yaf-view-simple.render" class="refentry">
 <div class="refnamediv">
<h1 class="refname">Yaf_View_Simple::render</h1>
<p class="verinfo">(Yaf &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">Yaf_View_Simple::render</span> &mdash; <span class="dc-title">Render a template</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-yaf-view-simple.render-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">function</span> <span class="methodname"><strong>Yaf_View_Simple::render</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$tpl</code></span>, <span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$vars</code><span class="initializer"> = NULL</span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="simpara">Renders a template and returns the result as a string. The template is included as a plain PHP script, so any PHP code in it is executed, and assigned variables are available under their names.</p>
   <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="simpara">Unlike <span class="methodname"><a href="yaf-view-simple.display.php" class="methodname">Yaf_View_Simple::display()</a></span>, the result is returned instead of being appended to the <span class="classname"><a href="class.yaf-response-abstract.php" class="classname">Yaf_Response_Abstract</a></span> body.</p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-yaf-view-simple.render-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">tpl</code></dt>
    <dd>
<p class="simpara">The path to the template, relative to the template directory set by <span class="methodname"><a href="yaf-view-simple.setscriptpath.php" class="methodname">Yaf_View_Simple::setScriptPath()</a></span> or <code class="literal">application.view.directory</code>.</p>
    </dd>
   
   
    <dt><code class="parameter">vars</code></dt>
    <dd>
<p class="simpara">Optional variables to assign for this render; they override assigned variables with the same name.</p>
    </dd>
   
  </dl>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-yaf-view-simple.render-returnvalues">
  <h3 class="title">Return Values</h3>
<p class="simpara">The rendered result as a string, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.</p>
 </div>


 <div class="refsect1 examples" id="refsect1-yaf-view-simple.render-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="methodname"><strong>Yaf_View_Simple::render()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
</span><span style="color: #007700">class </span><span style="color: #0000BB">ProductController </span><span style="color: #007700">extends </span><span style="color: #0000BB">Yaf_Controller_Abstract
</span><span style="color: #007700">{
    public function </span><span style="color: #0000BB">detailAction</span><span style="color: #007700">()
    {
        </span><span style="color: #FF8000">/* render the template and post-process the result */
        </span><span style="color: #0000BB">$html </span><span style="color: #007700">= </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getView</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">render</span><span style="color: #007700">(</span><span style="color: #DD0000">"product/detail.phtml"</span><span style="color: #007700">, array(
            </span><span style="color: #DD0000">"name"  </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"Yaf in Action"</span><span style="color: #007700">,
            </span><span style="color: #DD0000">"price" </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"29.90"</span><span style="color: #007700">,
        ));

        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">setBody</span><span style="color: #007700">(</span><span style="color: #0000BB">$html</span><span style="color: #007700">);
        return </span><span style="color: #0000BB">false</span><span style="color: #007700">; </span><span style="color: #FF8000">// skip auto-rendering
    </span><span style="color: #007700">}
}
</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
   </div>

  </div>
  <div class="example" id="example-2">
   <p><strong>Example #2 Template example</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000">&lt;h1&gt;<span style="color: #0000BB">&lt;?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">$name</span><span style="color: #007700">; </span><span style="color: #0000BB">?&gt;</span>&lt;/h1&gt;
&lt;p&gt;Price: <span style="color: #0000BB">&lt;?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">$price</span><span style="color: #007700">; </span><span style="color: #0000BB">?&gt;</span> EUR&lt;/p&gt;</code></pre></div>
   </div>

   <div class="example-contents"><p>The above example will output
something similar to:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">&lt;h1&gt;Yaf in Action&lt;/h1&gt;
&lt;p&gt;Price: 29.90 EUR&lt;/p&gt;</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-yaf-view-simple.render-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="yaf-view-simple.display.php" class="methodname" rel="rdfs-seeAlso">Yaf_View_Simple::display()</a> - Render and store a template in the response</span></li>
   <li><span class="methodname"><a href="yaf-view-simple.eval.php" class="methodname" rel="rdfs-seeAlso">Yaf_View_Simple::eval()</a> - Render a template string</span></li>
   <li><span class="methodname"><a href="yaf-view-simple.assign.php" class="methodname" rel="rdfs-seeAlso">Yaf_View_Simple::assign()</a> - Assign a variable to the view</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>