Name: zend-expressive-twigrenderer
Owner: Zend Framework
Description: Twig integration for Expressive
Created: 2015-10-11 01:49:05.0
Updated: 2018-05-07 22:17:49.0
Pushed: 2018-04-09 20:49:35.0
Homepage: null
Size: 326
Language: PHP
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Provides Twig integration for Expressive.
Install this library using composer:
mposer require zendframework/zend-expressive-twigrenderer
We recommend using a dependency injection container, and typehint against container-interop. We can recommend the following implementations:
composer require zendframework/zend-servicemanager
composer require mouf/pimple-interop
composer require aura/di
The included Twig extension adds support for url generation. The extension is automatically activated if the UrlHelper and ServerUrlHelper are registered with the container.
path
: Render the relative path for a given route and parameters. If there
is no route, it returns the current path.
ath('article_show', {'id': '3'}) }}
rates: /article/3
path
supports optional query parameters and a fragment identifier.
ath('article_show', {'id': '3'}, {'foo': 'bar'}, 'fragment') }}
rates: /article/3?foo=bar#fragment
By default the current route result is used where applicable. To disable this
the reuse_result_params
option can be set.
ath('article_show', {}, {}, null, {'reuse_result_params': false}) }}
url
: Render the absolute url for a given route and parameters. If there is
no route, it returns the current url.
rl('article_show', {'slug': 'article.slug'}) }}
rates: http://example.com/article/article.slug
url
also supports query parameters and a fragment identifier.
rl('article_show', {'id': '3'}, {'foo': 'bar'}, 'fragment') }}
rates: http://example.com/article/3?foo=bar#fragment
By default the current route result is used where applicable. To disable this
the reuse_result_params
option can be set.
rl('article_show', {}, {}, null, {'reuse_result_params': false}) }}
absolute_url
: Render the absolute url from a given path. If the path is
empty, it returns the current url.
bsolute_url('path/to/something') }}
rates: http://example.com/path/to/something
asset
Render an (optionally versioned) asset url.
sset('path/to/asset/name.ext', version=3) }}
rates: path/to/asset/name.ext?v=3
To get the absolute url for an asset:
bsolute_url(asset('path/to/asset/name.ext', version=3)) }}
rates: http://example.com/path/to/asset/name.ext?v=3
If you use the zend-component-installer
the factories are configured automatically for you when requiring this package
with composer. Without the component installer, you need to
include the ConfigProvider
in your
config/config.php
.
Optional configuration can be stored in config/autoload/templates.global.php
.
plates' => [
'extension' => 'file extension used by templates; defaults to html.twig',
'paths' => [
// namespace / path pairs
//
// Numeric namespaces imply the default/main namespace. Paths may be
// strings or arrays of string paths to associate with the namespace.
],
g' => [
'cache_dir' => 'path to cached templates',
'assets_url' => 'base URL for assets',
'assets_version' => 'base version for assets',
'extensions' => [
// extension service names or instances
],
'runtime_loaders' => [
// runtime loaders names or instances
],
'globals' => [
// Global variables passed to twig templates
'ga_tracking' => 'UA-XXXXX-X'
],
'timezone' => 'default timezone identifier, e.g.: America/New_York',
'optimizations' => -1, // -1: Enable all (default), 0: disable optimizations
'autoescape' => 'html', // Auto-escaping strategy [html|js|css|url|false]
See the Expressive Twig documentation.