Skip to content

Commit

Permalink
Adds application integration for stand-alone usage to the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
froschdesign authored and michalbundyra committed Oct 11, 2019
1 parent f2b0613 commit 025ca34
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
69 changes: 69 additions & 0 deletions docs/book/application-integration/stand-alone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Stand-Alone

The view and all view-helpers of zend-view can also be used stand-alone.

## The View

### Setup

[Create the a renderer, set a resolver for templates](../php-renderer.md#usage)
and initialize the view, e.g. `public/index.php`:

```php
// Create template resolver
$templateResolver = new Zend\View\Resolver\TemplatePathStack(
[
'script_paths' => [__DIR__ . '/../view'],
]
);

// Create the renderer
$phpRenderer = new Zend\View\Renderer\PhpRenderer();
$phpRenderer->setResolver($templateResolver);

// Initialize the view
$view = new Zend\View\View();
$view->getEventManager()->attach(
Zend\View\ViewEvent::EVENT_RENDERER,
function () use ($phpRenderer) {
return $phpRenderer;
}
);
```

### Create View Script

[Create a view script](../view-scripts.md), e.g. `view/index.phtml`:

```php
<h1><?= $headline ?></h1>
```

### Create View Model and render Output

Extend the script in `public/index.php`, add a view model and render the output:

```php
// Create view model
$viewModel = new ViewModel(['headline' => 'Example']);
$viewModel->setTemplate('index.phtml');

// Render
echo $view->render($viewModel); // <h1>Example</h1>
```

## View Helpers

### Setup

Create the renderer:

```php
$renderer = new Zend\View\Renderer\PhpRenderer();
```

### Using Helper

```php
echo $renderer->doctype(Zend\View\Helper\Doctype::HTML5); // <!DOCTYPE html>
```
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ nav:
- "Advanced usage of helpers": helpers/advanced-usage.md
- Cookbook:
- "Setting module-specific Layouts": cookbook/setting-module-specific-layouts.md
- "Application Integration":
- "Stand-Alone": application-integration/stand-alone.md
site_name: zend-view
site_description: 'Flexible view layer supporting and providing multiple view layers, helpers, and more.'
repo_url: 'https://github.com/zendframework/zend-view'

0 comments on commit 025ca34

Please sign in to comment.