views:

253

answers:

1

I'm trying to convert the John Resig's Templating Engine to work with PHP.

Essentially what I would like to achieve is the ability to use certain Kohana Views via a JavaScript templating engine, that way I can use the same views for both a standard PHP request and a jQuery AJAX request.

I'm starting with the basics and would like to be able to convert

http://github.com/nje/jquery-tmpl/blob/master/jquery.tmpl.js

To work with php like so...

### From This ###
<li><a href="{%= link %}">{%= title %}</a> - {%= description %}</li>
### Into This ###
<li><a href="<?= $link ?>"><?= $title ?></a> - <?= description ?></li>

The RexEx in it is a bit over my head and it's apparently not as easy as changing the %} to ?> in lines 148 to 158. Any help would be highly appreciated. I'm also not sure of how to take care of the $ difference that PHP variables have.

Thanks,

Serhiy

A: 

Since I've gotten no pointers in how to do this all in pure JS I've thought of another method. Any advice or pointers on this method would be highly appreciated as well. I was thinking of writing my views in HAML using kohaml to parse them.

http://github.com/transphorm/kohaml

Then tweaking the kohaml interpreter a bit to spit out JS Templates for me as well. What do you guys think of tackling the problem that way?

Serhiy