nitronet/fwk-twig

dev-master 2016-06-03 12:33 UTC

This package is not auto-updated.

Last update: 2024-10-26 16:10:53 UTC


README

Brings Twig template engine support for Fwk\Core Applications.

Installation

1: Install the sources

Via Composer:

{
    "require": {
        "nitronet/fwk-twig": "dev-master",
    }
}

If you don't use Composer, you can still download this repository and add it to your include_path PSR-0 compatible

2: Defines Twig as a Service

Define a Twig_Environment instance in your Di Container, and configure it the way you want:

<!-- Twig_Environment Configuration -->
<array-definition name="twig.config">
    <param key="debug">true</param>
</array-definition>

<!-- Twig_Loader definition -->
<class-definition name="twig.loader" class="\Twig_Loader_Filesystem" shared="true">
    <!-- :packageDir = directory of this .xml file -->
    <argument>:packageDir/path/to/templates</argument>
</class-definition>

<!-- Twig_Environment definition -->
<class-definition name="twig" class="\Twig_Environment" shared="true">
    <argument>@twig.loader</argument>
    <argument>@twig.config</argument>
</class-definition>

3: Register Twig ResultType

Registers a new ResultType in fwk.xml:

<result-type name="twig" class="FwkTwig\TwigResultType">
    <param name="twigService">twig</param>
</result-type>

4: Enjoy!

Use the ResultType where you want:

<action name="Home" shortcut="MyApp\Controllers\Home:show">
    <result name="success" type="twig">
        <param name="file">home.twig</param>
    </result>
</action>

Contributions / Community