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

Commit

Permalink
Merge ab71bdc into 8bad7f9
Browse files Browse the repository at this point in the history
  • Loading branch information
froschdesign committed Aug 20, 2019
2 parents 8bad7f9 + ab71bdc commit f36765e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
69 changes: 69 additions & 0 deletions doc/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 @@ -30,6 +30,8 @@ pages:
- Placeholder: helpers/placeholder.md
- Url: helpers/url.md
- "Advanced usage of helpers": helpers/advanced-usage.md
- "Application Integration":
- "Stand-Alone": application-integration/stand-alone.md
site_name: zend-view
site_description: zend-view
repo_url: 'https://github.com/zendframework/zend-view'
Expand Down

0 comments on commit f36765e

Please sign in to comment.