An alternative Template Engine for Play Framework : Cambridge

831 views
Skip to first unread message

Erdinc Yilmazel

unread,
Feb 16, 2011, 1:25:05 AM2/16/11
to play-fr...@googlegroups.com
A Template Engine that I've developed for Java (http://cambridge.googlecode.com) can now be used with Play Framework as a replacement or along with the built in template engine. 
Cambridge brings a different approach to templating where all the template files are valid html documents. It supports all the features of Play Framework and my experiments show 2.5 times faster
page rendering compared to the built in Play Framework template engine.

Here is the wiki page on how to use Cambridge templates in your Play Framework application : http://code.google.com/p/cambridge/wiki/UsingWithPlayFramework
and here is a blog post of mine which compares Cambridge to other template engines like Velocity and Freemarker (http://blog.erdincyilmazel.com/2011/02/10/comparing-cambridge-template-engine-with-jsp-velocity-freemarker-and-play-framework-templates)

Just a few minutes ago I've released version 0.2-RC of Cambridge. I'm now spending my time in improving the documentation and finishing the integration with popular web frameworks. An earlier version of Cambridge has been used in production on a very high volume website for the past 8 months. Any comments, bug reports are highly appreciated.

I hope this might be a good use to many developers who use Play Framework.

Thanks!

- Erdinc

Mickael Gentil

unread,
Feb 16, 2011, 3:22:18 AM2/16/11
to play-fr...@googlegroups.com
Hello,

I've take a look. The tags are brilliants. It seems like ColdFusion :)

Do you have made test between JAPID and CAMBRIDGE?

Thanks for you work.

regards
Mickaël

GrailsDeveloper

unread,
Feb 16, 2011, 4:14:55 AM2/16/11
to play-framework
Well I think a benefit of japid is that it's type-safe, because each
template will be compiled. Furthermore the are plans to get a code-
completion-editor.

CAMBRIDGE has the advantage, that it's pure html, so it's make
prototyping easier. On the other hand in most projects you use tags
and with a tag the html becomes invalid or don't show really a correct
page.

However a nice and interesting work. Thanks for sharing it.

Niels


On 16 Feb., 09:22, Mickael Gentil <mickael.gen...@gmail.com> wrote:
> Hello,
>
> I've take a look. The tags are brilliants. It seems like ColdFusion :)
>
> Do you have made test between JAPID and CAMBRIDGE?
>
> Thanks for you work.
>
> regards
> Mickaël
>
> On Wed, Feb 16, 2011 at 7:25 AM, Erdinc Yilmazel <erd...@yilmazel.com>wrote:
>
> > A Template Engine that I've developed for Java (
> >http://cambridge.googlecode.com) can now be used with Play Framework as a
> > replacement or along with the built in template engine.
> > Cambridge brings a different approach to templating where all the template
> > files are valid html documents. It supports all the features of Play
> > Framework and my experiments show 2.5 times faster
> > page rendering compared to the built in Play Framework template engine.
>
> > Here is the wiki page on how to use Cambridge templates in your Play
> > Framework application :
> >http://code.google.com/p/cambridge/wiki/UsingWithPlayFramework
> > and here is a blog post of mine which compares Cambridge to other template
> > engines like Velocity and Freemarker (
> >http://blog.erdincyilmazel.com/2011/02/10/comparing-cambridge-templat...
> > )

Julien Tournay

unread,
Feb 16, 2011, 7:20:37 AM2/16/11
to play-fr...@googlegroups.com, GrailsDeveloper
Hi,

Your template engine sounds interesting, reminds me Wicket /Tapestry5 templates.
Just one remark thought, in your examples, you're completely missusing play's default template engine, so obviously, it's much more verbose than expected.

For example, nobody would write:

 %{
if (entries.size() > 0) {
   for (entry in entries) {
%}
some html here
%{
  }
}
}%

but you should use the list tag:

#{list items:entries, as:'entry'}
 some html here
#{/list items}

jto.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.




--
Real Programmers don't need comments-- the code is obvious.

Erdinc Yilmazel

unread,
Feb 16, 2011, 9:43:52 AM2/16/11
to play-fr...@googlegroups.com
Thanks for pointing this out, I will correct the examples.

Erdinc Yilmazel

unread,
Feb 18, 2011, 12:31:23 AM2/18/11
to play-fr...@googlegroups.com
Thanks for all the Play Framework users who emailed me about various issues in the package that I initially released. Now you can find an updated package (version 0.2.rc) from google code which includes bug fixes.

I also uploaded a sample play framework application, which I used to make performance comparisons. According to Jmeter, for the test page that I created, Play Template Engine takes 680 milliseconds on average to render the html. On the other hand Cambridge takes only 183 milliseconds.

Please have a look at http://code.google.com/p/cambridge/wiki/UsingWithPlayFramework for updated documentation/comparison and get the sample application from http://cambridge.googlecode.com/files/playtest.tar.gz to start Playing with Cambridge Templates.

Erdinc

beb

unread,
Feb 21, 2011, 5:14:06 AM2/21/11
to play-framework
Very nice,

There is a small issue in the playtest.tar.gz
You should replace the route to the controller by Cambridge.index
instead of Application.index

Erik

On 18 fév, 06:31, Erdinc Yilmazel <erd...@yilmazel.com> wrote:
> Thanks for all the Play Framework users who emailed me about various issues
> in the package that I initially released. Now you can find an updated
> package (version 0.2.rc) from google code which includes bug fixes.
>
> I also uploaded a sample play framework application, which I used to make
> performance comparisons. According to Jmeter, for the test page that I
> created, Play Template Engine takes 680 milliseconds on average to render
> the html. On the other hand Cambridge takes only 183 milliseconds.
>
> Please have a look athttp://code.google.com/p/cambridge/wiki/UsingWithPlayFrameworkfor updated
> documentation/comparison and get the sample application fromhttp://cambridge.googlecode.com/files/playtest.tar.gzto start Playing with
> Cambridge Templates.
>
> Erdinc
>
> On Wed, Feb 16, 2011 at 9:43 AM, Erdinc Yilmazel <erd...@yilmazel.com>wrote:
>
>
>
>
>
>
>
> > Thanks for pointing this out, I will correct the examples.
>

v6ak

unread,
Apr 14, 2011, 4:06:20 AM4/14/11
to play-fr...@googlegroups.com
That's nice. I've some notes and ideas:

1. Using a:foreach reminds me Nette tepmlates. (Unfortunately, there is no good English documentation for Nette.)

2. What about a:inner-foreach?:
<ul a:inner-foreach="..." ...>
   <li>...
</ul>

3. a:next is IMHO dirty. What about handling null/Option values?
<td class='${if(iter.even), "even", null}'>

<td class='${if(iter.even), Some("even"), Null}'> // Some and None comes from Scala.

<td class='${List(
  "foo",
  if(iter.even), "even", null)
}'>

4. Is there a possibility to use more than one-element block? I mean something like:
<if ...>
  <div id="register">....</div>
  <div id="login">....</div>
</if>

5. What about HAML? :)

6. Does it support context-sensitive escaping?

Regards,
Vít Šesták 'v6ak'

Watter

unread,
Jun 5, 2011, 11:06:07 PM6/5/11
to play-framework
I realize that this is an old thread, so sorry to resurrect, but I'm
curious to hear if anyone is using Cambridge in their projects? In any
project of significant size I've been on, there is always a web
developer doing the HTML/CSS work and of the template options for play
I've seen, Cambridge would appear to be by far the most friendly to
someone like that.On our current projects we use Wicket and it's been
fairly good in that regard. Our web developer picked up on the parts
that applied to him very quickly.

If you're using Cambridge, what, if any, limitations have you run
across as compared to the default Play! groovy templating?

Matt

Rakesh Waghela

unread,
Jun 6, 2011, 11:26:33 AM6/6/11
to play-fr...@googlegroups.com
In recent Template related discussions I have highlighted the Cambridge.. W to are thinking of using Cambridge only in one of the pilot app we are planning to develop.
On thread compared all the Template Engines available for Play ! ( Scala/Java ), just have a look there..

GrailsDeveloper

unread,
Jun 7, 2011, 4:31:29 AM6/7/11
to play-framework
Hi,

Cambridge is in deed very good if you have a gui.designer, which just
create the UI. The question I have, is this really a good pattern. I
mean in simple situations it work pretty well, but in real world, I
guess it's a good idea to create tags and use them. Therefor you must
have a running server. So the designer can't work with his preferred
tool. How is you experience with this issue?

Niels

Rakesh Waghela

unread,
Jun 7, 2011, 4:37:17 AM6/7/11
to play-fr...@googlegroups.com
tags ?

have a look at Cambridge Source..

http://code.google.com/p/cambridge/source/browse/trunk/cambridge-core/src/main/java/cambridge/tags/DummyTag.java

did you get any idea from it ? use case ?

More Info for developers here.. http://code.google.com/p/cambridge/wiki/DevelopersGuide

GrailsDeveloper

unread,
Jun 7, 2011, 6:45:46 AM6/7/11
to play-framework
Ok Campridge doesn't seem to support custom tags :-( But it has
includes, so there you have the same problem, that the designer see a
different page than the user.
Niels

On 7 Jun., 10:37, Rakesh Waghela <javain...@gmail.com> wrote:
> tags ?
>
> have a look at Cambridge Source..
>
> http://code.google.com/p/cambridge/source/browse/trunk/cambridge-core...

Rakesh Waghela

unread,
Jun 7, 2011, 6:50:20 AM6/7/11
to play-fr...@googlegroups.com
I think it does..

look at the java doc of this class..

http://code.google.com/p/cambridge/source/browse/trunk/cambridge-core/src/main/java/cambridge/DynamicTag.java

/**
 * If you want you write a custom tag that will be rendered with the custom
 * logic that you define, you should extend DynamicTag and override the TagNode
 * methods that you want.
 *
 * The dynamic tag implementation that you created needs to be registered with the
 * Cambridge singleton by invoking the bindTag method.
 *
 * This class is for advanced used only and should be only needed if you want to write a tag library.
 */
public abstract class DynamicTag extends TagNode.............

GrailsDeveloper

unread,
Jun 7, 2011, 2:19:40 PM6/7/11
to play-framework
You miss the point. It's not important for me if cambridge support
tags or not. In the normal doku I don't see it. The point is, that a
HTML-Designer don't know tags and doesn't know how to use. So I wonder
if it is really a good development model to split between web
developer and normal developer. This was the question. Matt seems to
have experience with it, so I asked him to share it.
Niels

On 7 Jun., 12:50, Rakesh Waghela <javain...@gmail.com> wrote:
> I think it does..
>
> look at the java doc of this class..
>
> http://code.google.com/p/cambridge/source/browse/trunk/cambridge-core...

Rakesh Waghela

unread,
Jun 8, 2011, 2:34:50 AM6/8/11
to play-fr...@googlegroups.com
"..The point is, that a HTML-Designer don't know tags and doesn't know how to use..."  It's equally applicable to all the template libraries , isn't it ?
Somewhere there will be a learning.. :)
Reply all
Reply to author
Forward
0 new messages