goat-node

Simple view engine for Express

goat-node

###Another Express view engine

Push get, post variables into $_GET, $_POST - coming soon..

(GOAT == 'Greatest of All Time') ? 'No..'

We were feeding goats at the petting zoo, and I thought about feeding data to an HTML template.

First of all, some reasons why another view/templating engine was worth a short time to put together.

Frankly, it gets no better than,

Hello <?=$name?>, how are you..  

(I don't use because unlike some people I don't like to type)

NO template engine to reference or load, by the way..

Almost all view engines are that, except with a new strange syntax to learn.

Now,

  1. Jade is good. Very nice. Terse == lovely. I wasn't crazy about having to learn it (Markdown either, as you can tell by the (!lovelyness) of my README),

After some practice I can sort-of get stuff done. BUT I use two environments, Nodejs and PHP v5.2. Jade for PHP v5.3> only, so says Mr. Google. :(
I'm not upgrading my PHP right now.

Need something more old-school compatible.

  1. Templates for every template engine I could find are not valid HTML. (Except Plates I believe) Something just icky about that. I want to match on Div ids ala Plates. But I want something very low on features. Small simple modules, pieced together. (Plus I want to get the 1st version out in 1 day)

  2. Logic in the template, programming constructs, just feels rigid and wrong.

  3. Custom syntaxes is more stuff to learn. I don't really need that. Only two things to know with feeding data to these templates.

Expressjs styley..

res.render('index', {name:'Goat'}

// this is index.html:

// you can guess what happens..

// need to handle arrays too

res.render('index', {name:'Goat', people:[{name:'chris', age:42}, {name:'paris', age:32}]}

        <div id='name'></div>
        <table id="">
            <tr>
                <th>name</th><th>age</th>
            </tr>
            <tr id="people">
                <td id="name"></td>
                <td id="age"></td>
            </tr>
        </table>
var render = require('php-node')({bin:"c://php//php.exe"});
 
render(__dirname+'/index.php', {}, function(er) {
    console.log(r);
})
 
// use PHP as view engine in Express 
var express = require('express'),
    app = express(),
    phpnode = require('php-node')({bin:"c:\\php\\php.exe"});
 
app.set('views', __dirname);
app.engine('php', phpnode);
app.set('view engine', 'php');
 
app.all('/index.php', function(reqres) {
   res.render('index');
})
 
var port = process.env.PORT || 3000;
app.listen(port, function() {
  console.log("Listening on " + port);
})