poirot/view

There is no license information available for the latest version (dev-devel) of this package.

Render View Templates.

dev-devel 2019-05-26 11:06 UTC

This package is auto-updated.

Last update: 2024-10-26 23:29:57 UTC


README

Render Response Views

$view = new P\View\ViewModelTemplate([
    'resolver_options' => [
        '*' => __DIR__.'/templates'
    ],
]);
$bind = new P\View\ViewModelDecorateFeatures(clone $view);
$bind->setRenderer(\Poirot\View\renderManipulatedVars());
$bind->onNotifyRender = function($parentView, $self) {
    // Lookin for template_name.php beside base template
    /** @var P\View\ViewModelTemplate $self */
    $self->setExtension('php');
    $self->setTemplate($parentView->getTemplate());
    $self->setVariables($parentView->variables());
};
$bind->afterRender = function($result, $parent, $self) {
    if (is_array($result)) {
        /** @var P\View\ViewModelTemplate $parent */
        $parent->variables()->import($result);
    }
};

$view->bind($bind);

echo $view->setVariables(['user'=>'This is user'])->setTemplate('main')->render();