php8.5
Home/ Manual/ yaf / yaf_view_simple/ Yaf_View_Simple::display

Yaf_View_Simple::display

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Render and store a template in the response

Description

Yaf_View_Simple::display(string $tpl, array $vars = NULL): bool

Renders a template and appends the result to the Yaf_Response_Abstract body.

Note

Unlike Yaf_View_Simple::render, the result is not returned but stored in the response, and Yaf_Application sends it when the response is emitted.

Parameters

tpl

The path to the template, relative to the template directory set by Yaf_View_Simple::setScriptPath or application.view.directory.

vars

Optional variables to assign for this template only; they override assigned variables with the same name.

Return Values

Returns true on success, or false on failure.

Examples

Yaf_View_Simple::display example

php
<?php
class IndexController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        $this->getView()->assign("title", "My Homepage");

        /* render index/index.phtml and store the result
         * in the response body */
        $this->getView()->display("index/index.phtml");

        return false; // we rendered ourselves, skip auto-rendering
    }
}
?>

Template example

php
<html>
 <head>
  <title><?php echo $title; ?></title>
 </head>
</html>

See Also

  • Yaf_View_Simple::render
  • Yaf_View_Simple::assign

Source: reference/yaf/yaf_view_simple/display.xml · from the official PHP manual (php/doc-en)