Git Product home page Git Product logo

mezzio-twigrenderer's Introduction

Twig Integration for Mezzio

Build Status

Provides Twig integration for Mezzio.

Installation

Install this library using composer:

$ composer require mezzio/mezzio-twigrenderer

We recommend using a dependency injection container, and typehint against container-interop. We can recommend the following implementations:

Twig Extension

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.

    {{ path('article_show', {'id': '3'}) }}
    Generates: /article/3

    path supports optional query parameters and a fragment identifier.

    {{ path('article_show', {'id': '3'}, {'foo': 'bar'}, 'fragment') }}
    Generates: /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.

    {{ path('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.

    {{ url('article_show', {'slug': 'article.slug'}) }}
    Generates: http://example.com/article/article.slug

    url also supports query parameters and a fragment identifier.

    {{ url('article_show', {'id': '3'}, {'foo': 'bar'}, 'fragment') }}
    Generates: 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.

    {{ url('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.

    {{ absolute_url('path/to/something') }}
    Generates: http://example.com/path/to/something
  • asset Render an (optionally versioned) asset url.

    {{ asset('path/to/asset/name.ext', version=3) }}
    Generates: path/to/asset/name.ext?v=3

    To get the absolute url for an asset:

    {{ absolute_url(asset('path/to/asset/name.ext', version=3)) }}
    Generates: http://example.com/path/to/asset/name.ext?v=3

Configuration

If you use the laminas-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.

'templates' => [
    '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.
    ],
],
'twig' => [
    '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]
    'auto_reload' => true, // Recompile the template whenever the source code changes
    'debug' => true, // When set to true, the generated templates have a toString() method
    'strict_variables' => true, // When set to true, twig throws an exception on invalid variables
],

Documentation

See the Mezzio Twig documentation.

mezzio-twigrenderer's People

Contributors

weierophinney avatar geerteltink avatar michalbundyra avatar 0nua avatar arueckauer avatar azjezz avatar froschdesign avatar koopzington avatar harikt avatar edigu avatar timdev avatar xerkus avatar alucic avatar dannym87 avatar elisdn avatar grafikart avatar tigerman55 avatar lucassabreu avatar boesing avatar ghostwriter avatar caeret avatar ncou avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.