Activate your free membership today | Log-in

Tuesday, March 14th, 2006

Ajax Templating – Separation of Layout and Logic

Category: PHP, Programming, Prototype

<p> In this informative blog entry, BorkWeb.com shares a method for creating a templating system generated wholely with Ajax and PHP.

While Ajax is the cause for the article, the heavy focus is on templating. For the past few years I have been using XTemplate as my templating library (I’m a PHP buff) and have been happily separating my logic from my layout…unitl I ran smack dab into the power of Javascript. My PHP still kept its separation from HTML as is the purpose of XTemplate, but it was my HTML that became littered with little nuggets of Javascript all over the place. No matter the method to my Ajax madness, this was my problem.

They step through the process, noting first what templating is really defined as and how it can be useful to just about anyone. They give their examples in PHP, but it can easily be conformed to just about any other language quickly and easily. They set up a templating situation where all seems ideal, except, of course, for one small problem – dynamic control of (javascript) user events in HTML elements on the page (onClick/onMouseOver/etc).

His solution? He uses the Behaviour libray that’s built on top of everyone’s favorite Javascript library, Prototype. With a few quick lines of Javascipt, a bulleted list is created so that, onClick the item selected will be removed from the list.

You can find out more about each of the projects mentioned from their homepages:

Related Content:

  • Apache Wicket with Ajax updates
    Improved AjaxTree/AjaxTreeTable functionality and simplified APIs are part of the latest version of Apache Wicket, a Java open source component based...
  • Direct Ajax - Goodbye to Ajax Deadly Sins
    A tech lead was assigned to enrich his company's "Expense Claim" application with Ajax technologies. At first, he planned to deliver the application...
  • Putting ASP.NET AJAX into action
    Alessandro Gallo is a Microsoft MVP in ASP.NET, an active contributor to the ASP.NET AJAX Control Toolkit and one of three authors of "ASP.NET AJAX in...
  • Sun releases Ajax framework
    Sun Microsystems Inc. announced the release of jMaki 1.0 a client/server framework for Ajax that part of the Sun Web Developer Pack (SWDP). The new...
  • ASP.NET AJAX released
    Microsoft's toolkit for incorporating Ajax functionality into ASP.NET applications has been released. The company is also giving ASP.NET AJAX full...

Posted by Chris Cornutt at 8:26 am
4 Comments

++++-
4.2 rating from 42 votes

4 Comments »

Comments feed TrackBack URI

What is seperation?

Comment by adriano — March 14, 2006

a bit too much js. no js, no website, not good ;)

Comment by shady — March 14, 2006

Dojo provides much the same facility through it’s widget system. Templates separate the view and behavior from the (hopefully) semantic markup that declares the widget in the page.

There’s also a large number of people that might take exception to the assertion that Prototype is “everyone’s favorite JavaScript library”.

Regards

Comment by Alex Russell — March 14, 2006

Behaviour.js is not built on Prototype.js at all – it’s completely standalone.

Comment by Aslak Hellesoy — March 14, 2006

Leave a comment

You must be logged in to post a comment.