2017 © Pedro Peláez
 

library blast-view

Standalone template renderer using templating engine from Zend Framework 2 - Zend\View.

image

mtymek/blast-view

Standalone template renderer using templating engine from Zend Framework 2 - Zend\View.

  • Thursday, August 13, 2015
  • by mtymek
  • Repository
  • 1 Watchers
  • 0 Stars
  • 44 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Blast\View

Standalone template renderer using templating engine from Zend Framework 2 - Zend\View., (*1)

You can use it to render PHTML files outside the context of ZF2 MVC, but with all Zend\View features: nested templates, view helpers, etc., (*2)

Example use cases:, (*3)

  • generating HTML from command line applications
  • rendering HTML e-mails
  • using Zend\View without other Zend Framework components

Build Status Coverage Status, (*4)

Installation

  1. Install package using composer:, (*5)

    $ composer require mtymek/blast-view ~0.5
    
  2. Add Blast\View to module list in your system configuration (config/application.config.php file)., (*6)

Configuration

Blast\View uses configuration keys similar to regular Zend application. Currently you can configure two options:, (*7)

  • location to view templates (template_path_stack key)
  • default layout (layout_template key)
return [
    'view_manager' => [
        'layout_template' => 'layout/layout.phtml',
        'template_path_stack' => [
            __DIR__ . '/../view',
        ],
    ],
];

Usage

Once installed, Blast\View module will register new service: Blast\View\View in application's main ServiceManager. It can be easily pulled from there to render templates outside of ZF2 MVC:, (*8)

use Zend\View\Model\ViewModel;
use Blast\View\View;

$viewModel = new ViewModel(
    [
        'name' => 'Mat'
    ]
);
$viewModel->setTemplate('index.phtml');

$view = $serviceManager->get(View::class);
echo $view->render($viewModel);

Layouts

Layout is just a parent ViewModel wrapping your main view script. It should be injected using setLayout() method before rendering main template:, (*9)

$layout = new ViewModel();
$layout->setTemplate('layout/layout.phtml');
$view->setLayout($layout);

$viewModel = new ViewModel();
$viewModel->setTemplate('index.phtml');
echo $view->render($viewModel);

Layout template has the same structure as in ZF2:, (*10)

<html>
<head>
</head>
<body>
    <?php echo $this->content ?>
</body>
</html>

View Helpers

Blast\View supports custom view helpers via view_helpers configuration key, in the same manner as ZF2 does. Here's an example config that registers foo view helper:, (*11)

return [
    'view_helpers' => [
        'invokables' => [
            'foo' => FooHelper::class,
        ]
    ],
];

The Versions

13/08 2015

dev-master

9999999-dev

Standalone template renderer using templating engine from Zend Framework 2 - Zend\View.

  Sources   Download

2-Clause BSD

The Requires

 

The Development Requires

template renderer view helper layout zend view

13/08 2015

0.6.1

0.6.1.0

Standalone template renderer using templating engine from Zend Framework 2 - Zend\View.

  Sources   Download

2-Clause BSD

The Requires

 

The Development Requires

template renderer view helper layout zend view

13/08 2015

0.6.0

0.6.0.0

Standalone template renderer using templating engine from Zend Framework 2 - Zend\View.

  Sources   Download

2-Clause BSD

The Requires

 

The Development Requires

template renderer view helper layout zend view

19/07 2015

0.5.1

0.5.1.0

Template renderer using templating engine from Zend Framework 2 - Zend\View.

  Sources   Download

2-Clause BSD

The Requires

 

The Development Requires

template renderer view helper layout zend view