# Grunt Twig Server

`twig-server` is a grunt plugin which replaces the usual [grunt-contrib-connect](https://github.com/gruntjs/grunt-contrib-connect) by a Silex server capable of interpreting twig templates.

## Getting Started

This plugin requires `php 5.4` as well as `grunt ~0.4.0`.

You may install this plugin with this command:

```bash
$ npm install grunt-twig-server --save-dev
```

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

```js
grunt.loadNpmTasks('grunt-twig-server');
```

You also need to install the php server:

```bash
$ cd server
$ composer install
```

## Usage examples

In this example, `grunt twig-server` (or more verbosely, `grunt twig-server:serve`)  will start a web server at `http://localhost:9000/`, with its base path set to the `app` directory relative to the gruntfile, and any tasks run afterwards will be able to access it.

```js
// Project configuration in your Gruntfile
grunt.initConfig({

    ...

    twigServer: {
        options: {
            port: 9000,
            // Change this to '0.0.0.0' to access the server from outside
            hostname: 'localhost',
            base: [
                '.tmp',
                'app'
            ]
        }
    }
```

In this case, browsing to `http://localhost:9000/pages/mypage.html` will evaluate the template in `app/pages/mypage.html.twig` (or `.tmp/pages/mypage.html.twig` if the first one does not exist), as well as serve all static files from `app/` (or `.tmp/` if it does not exist).

## Serve task
Run this task with the `grunt twig-server:serve` command.

It will output:

```
Started Twig Server web server on 127.0.0.1:9000.
```

### Options

#### port
Type: `Integer`  
Default: `8000`

The port on which the webserver will respond.  
The task will fail if the specified port is already in use.

#### hostname
Type: `String`  
Default: `'localhost'`

The hostname the webserver will use.

#### base
Type: `String` or `Array`
Default: `'.'`

The base (or root) directory from which files will be served. Defaults to the project Gruntfile's directory.

Can be an array of bases to serve multiple directories. The last base given will be the directory to become browse-able.
