Giter VIP home page Giter VIP logo

zfctwig's Introduction

ZfcTwig Module for Zend Framework 2 Master Branch Build Status

ZfcTwig is a module that integrates the Twig templating engine with Zend Framework 2.

Installation

  1. Add "zf-commons/zfc-twig": "dev-master" to your composer.json file and run php composer.phar update.
  2. Add ZfcTwig to your config/application.config.php file under the modules key.

Configuration

ZfcTwig has sane defaults out of the box but offers optional configuration via the zfctwig configuration key. For detailed information on all available options see the module config file class.

Documentation

Setting up Twig extensions

Extensions can be registered with Twig by adding the FQCN to the extensions configuration key which is exactly how the ZfcTwig extension is registered.

// in module configuration or autoload override
return array(
    'zfctwig' => array(
        'extensions' => array(
            // an extension that uses no key
            'My\Custom\Extension',

            // an extension with a key so that you can remove it from another module
            'my_custom_extension' => 'My\Custom\Extension'
        )
    )
);

Configuring Twig loaders

By default, ZfcTwig uses a Twig_Loader_Chain so that loaders can be chained together. A convenient default is setup using a filesystem loader with the path set to module/Application/view which should work out of the box for most instances. If you wish to add additional loaders to the chain you can register them by adding the service manager alias to the loaders configuration key.

// in module configuration or autoload override
return array(
    'zfctwig' => array(
        'loaders' => array(
            'MyTwigFilesystemLoader'
        )
    )
);

// in some module
public function getServiceConfiguration()
{
    return array(
        'factories' => array(
            'MyTwigFilesystemLoader' => function($sm) {
                return new \Twig_Loader_Filesystem('my/custom/twig/path');
            }
        )
    );
}

Using ZF2 View Helpers

Using ZF2 view helpers is supported through the ZfcTwig\Twig\Func\ViewHelper function.

{# Simple view helper echo #}
{{ docType() }}

{# Echo with additional methods #}
{{ headTitle('My Company').setSeparator('-') }}

{# Using a view helper without an echo #}
{% do headTitle().setSeparator('-') %}

{# Combining view helpers #}
{% set url = ( url('my/custom/route') ) %}

Examples

Example .twig files for the skeleton application can be found in the examples folder.

zfctwig's People

Contributors

cosmin-harangus avatar bakura10 avatar evandotpro avatar alexdenvir avatar hikaru-shindo avatar rmasters avatar

Watchers

James Cloos avatar Nikolay Murha avatar  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.