Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Adds application integration for stand-alone usage to the documentation #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'