grunt-twig-server

0.1.0 • Public • Published

Grunt Twig Server

twig-server is a grunt plugin which replaces the usual 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:

$ 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:

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

You also need to install the php server:

$ 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.

// 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.

Readme

Keywords

none

Package Sidebar

Install

npm i grunt-twig-server

Weekly Downloads

1

Version

0.1.0

License

none

Last publish

Collaborators

  • knplabs