Monday, June 18th, 2007

plainTemplate & phpQuery

Category: jQuery, PHP

plainTemplate is a new library that aims to separate out an HTML template from design and coding, thanks to selectors.

The designer works by simply using HTML in any way they wish, and then the programmer:

  • Write selectors based on HTML structure
  • Pass those selectors and Controller data to plainTemplate
  • plainTemplate parses template, removing designer’s example data
  • If there is a need, you can manually write template proccessing rules with phpQuery – a jQuery port to PHP
  • Everything caches to pure, human-readable PHP file, similar to that one written with no template engine
  • From one HTML file You can build several templates
  • Once the Designer updates the file, the cached template updates itself transparently

phpQuery is a port of jQuery that let’s you do things like this:

  1. _('body div.myClass.myClass2 ul > li:first')
  2.     ->parent()
  3.         ->prepend('<li>my new first LI</li>')
  4.         ->parents('.myClass')
  5.             ->remove()
  6.             ->end()
  7.         ->appendTo('body');

Download plainTemplate

Posted by Dion Almaer at 7:35 am

3.2 rating from 50 votes


Comments feed TrackBack URI

Ha-ha, nice!

Comment by Калоян К. Цветков — June 18, 2007

This is an interesting idea. I have a feeling it would be pretty frustrating in the average project situation because it shifts so much responsibility to the controller from the view. Probably a bit of a learning curve in how to use it well, too. That said, I bet there are situations where this would work really well – especially with certain designers.

Comment by Mark Guinn — June 18, 2007

I think the sub-project phpQuery actually has me more interested than the templating project…

Comment by Shawn — June 18, 2007

Uh, doesn’t this completely break the whole concept of separating layout from data?

Comment by yoink — June 18, 2007

Shawn — exactly. I was looking for such thing for php and all I found was a getElementsBySelector function which is a part of Symphony framework. I hope this jQuery clone will get enough attention from the community.

Comment by misha — June 19, 2007

This is all about separating layout from data :) Eg with Smarty You have to manually paste vars inside template. Var is data. With selectors You define classes where the data should be. You even dont have to define classes – by default plainTemplate pastes DB data into LIs in UL.

There are several benefits from this approach like fully working examples for clients, transparent updates, strongly reusable code and /whats most important/ clean (plain) templates.

This is first release so dont expect much, but basic functionality is on the place (especially phpQuery is almost ready).

One thing not mentioned in post – ability to save You work in firebug ;) I like it very much myself.

Comment by Tobiasz Cudnik — June 19, 2007

This phpQuery will be especially useful for writing plugins for existing scripts – it will be possible to change templates without touching them directly.

Comment by misha — June 19, 2007

This is interesting but it begs the question – where should DOM modification decisions be made?
– on the client side (i.e. in the browser) ? In this model – more of a traditional MVC where the view resides on the client – the client subscribes to data changes (the model) and updates the UI accordingly. Would you need something like Silverlight to execute the php on the client or should JQuery be used directly?
– on the server side where server side code, such as php in this case, generates the output to the browser? With this more traditional web development (where the view actually is generated on the server), couldn’t this be wrapped in declarative markup (such as W3C’s remote events for XML – REX – or Apache XAP’s XModify) – for the sake of consistency with many data centric and other frameworks as well as brute force html (angle bracket programming)?

Does it come down to convenience vs speed?

Comment by Ben — July 6, 2007

I wish I knew how to program like you dudes… I need some nice websites for my marketing, maybe I could hire a few sometime. I’m into downloading modules and stuff like that.

I’m starting programming now, maybe that will help me be able to build some cool stuff :)

Comment by Christopher Stigson — October 26, 2007

i tried smarty and other templating framework for PHP but PHPquery is one of my best choice

Comment by mountlaurel — January 10, 2008

for me PHpQuery rocks! i have been using it for 2 months and its great!

Comment by mountlaurel — March 1, 2008

There is new version supporting server-side Ajax, Events and much more, check it out:

Release notes here:

Comment by TobiaszCudnik — September 19, 2008

Leave a comment

You must be logged in to post a comment.