PHP 8.6.0 Beta 3 is available for testing

Yaf_View_Interface::render

(Yaf >=1.0.0)

Yaf_View_Interface::renderRenderiza una plantilla

Descripción

abstract public function Yaf_View_Interface::render(string $tpl, array $tpl_vars = NULL): string

Renderiza una plantilla y devuelve el resultado.

Parámetros

tpl

La ruta de la plantilla, relativa al directorio de plantillas.

tpl_vars

Variables opcionales a asignar solo para esta plantilla; tienen prioridad sobre las variables asignadas con el mismo nombre.

Valores devueltos

El resultado renderizado como cadena, o false en caso de error.

Ejemplos

Ejemplo #1 Ejemplo de Yaf_View_Interface::render()

<?php
class MyView implements Yaf_View_Interface
{
    private $tpl_dir;
    private $vars = array();

    public function __construct($template_dir, $options = null)
    {
        $this->tpl_dir = $template_dir;
    }

    public function assign($name, $value = null)
    {
        $this->vars[$name] = $value;
        return true;
    }

    public function display($tpl, $tpl_vars = null)
    {
        echo $this->render($tpl, $tpl_vars);
        return true;
    }

    public function render($tpl, $tpl_vars = null)
    {
        extract($this->vars);
        if ($tpl_vars !== null) {
            extract($tpl_vars);
        }
        ob_start();
        include $this->tpl_dir . "/" . $tpl;
        return ob_get_clean();
    }

    public function setScriptPath($template_dir)
    {
        $this->tpl_dir = $template_dir;
        return $this;
    }

    public function getScriptPath()
    {
        return $this->tpl_dir;
    }
}

/* se conecta el motor de vistas personalizado al despachador en el bootstrap */
class Bootstrap extends Yaf_Bootstrap_Abstract
{
    public function _initView(Yaf_Dispatcher $dispatcher)
    {
        $dispatcher->setView(new MyView(APPLICATION_PATH . "/views"));
    }
}
?>

Véase también

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top