PHPackages                             cedriclombardot/twig-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. cedriclombardot/twig-generator

ActiveLibrary[Templating &amp; Views](/categories/templating)

cedriclombardot/twig-generator
==============================

A generator for PHP code based on Twig template engine

v1.1.0(11y ago)66133.2k↓42.9%25[3 PRs](https://github.com/cedriclombardot/TwigGenerator/pulls)6MITPHPPHP &gt;=5.3.0

Since Nov 9Pushed 10y ago4 watchersCompare

[ Source](https://github.com/cedriclombardot/TwigGenerator)[ Packagist](https://packagist.org/packages/cedriclombardot/twig-generator)[ RSS](/packages/cedriclombardot-twig-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (6)

TwigGenerator [![project status](https://camo.githubusercontent.com/3b2f8e6ae2e5d14027d882b3e61db23835d5d905bc6dd6dc3b27bd050c0061e4/687474703a2f2f7374696c6c6d61696e7461696e65642e636f6d2f6365647269636c6f6d626172646f742f5477696747656e657261746f722e706e67)](https://camo.githubusercontent.com/3b2f8e6ae2e5d14027d882b3e61db23835d5d905bc6dd6dc3b27bd050c0061e4/687474703a2f2f7374696c6c6d61696e7461696e65642e636f6d2f6365647269636c6f6d626172646f742f5477696747656e657261746f722e706e67) [![build status](https://camo.githubusercontent.com/2296d1b2a5acbe18a5eedfb95af5955196f4809ce8c7917cfe2db351204dc159/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6365647269636c6f6d626172646f742f5477696747656e657261746f722e706e67)](https://camo.githubusercontent.com/2296d1b2a5acbe18a5eedfb95af5955196f4809ce8c7917cfe2db351204dc159/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6365647269636c6f6d626172646f742f5477696747656e657261746f722e706e67)\#
=====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#twiggenerator--)

TwigGenerator is a PHP code generator based on the [Twig](https://github.com/fabpot/Twig) template engine. It leverages the power of Twig templates to simplify the generation of PHP code, to make it more extensible, and more readable.

Installation
------------

[](#installation)

Checkout this GitHub repository and setup the composer dependencies (Twig and Symfony ClassLoader):

```
git clone https://github.com/cedriclombardot/TwigGenerator.git
cd TwigGenerator
wget -nc http://getcomposer.org/composer.phar
php composer.phar install

```

Usage
-----

[](#usage)

To generate PHP classes, you need to create a "Builder", and one or more Twig templates. Then, add the new Builder to a "Generator", and generate the result.

### Creating a Builder class

[](#creating-a-builder-class)

First, create a class extending `TwigGenerator\Builder\BaseBuilder` - no need for methods at start.

```
