Page 1 of 2

bye bye patTemplate

Posted: Fri Jul 07, 2006 10:54 am
by azrulrhm
trying it for 45 mins... too hard to do anything simple, but it looks like easy to create something complicated. I am giving up.. rolling my own, super simple template system ...  :'(  bye bye patTemplate!

Re: bye bye patTemplate

Posted: Tue Jul 11, 2006 9:26 pm
by mmx
Have you tried the tutorials on Melonfire. They provide a lot of examples for working with master templates, subtemplates, conditional templates, etc. Follow these links:

http://www.melonfire.com/community/colu ... php?id=130

http://www.melonfire.com/community/colu ... php?id=132

The above articles are dated, but they may help you over the basics.

Re: bye bye patTemplate

Posted: Tue Jul 11, 2006 10:25 pm
by ianmac
Is there any thought on revisiting the use of patTemplate?  I tried various experiments with patTemplate and it was definitely a love-hate relationship.  There were something which I used it for an it was great - it make some things very easy and very clean.

Other things were not quite as simple though, and either couldn't be done by design or by bug.

This in itself wouldn't be much cause for reconsideration, but it also looks like development has stopped on these packages (am I wrong in this?)  An alpha version was released in April 2005 of 3.1...  nothing has happened since.  I tried to look at the SVN, but it was down.  The guy who is as far as I know the lead developer has not posted on the forum since March 25th.

Perhaps we ought to revisit this and check the status of patTemplate?  I know that we have already included in the core since 1.0, but on the other hand, the new API is fairly modular so it shouldn't be too difficult to change (although I guess the syntax extends past the API).

I guess bottom line, if this is a library that is not going to serve its purpose (and maybe we need to poll the community), then it is best to make that change now before we go further down the patTemplate road (which hasn't been adopted to widely as of now, AFAIK, because there is a substantial performance hit involved with it)...

Thoughts?
Ian

Re: bye bye patTemplate

Posted: Tue Jul 11, 2006 10:57 pm
by masterchief
Hi Ian

What are the problems?  I can probably give you some help - or if nothing else we know what problems you have faced to know what to look for in selecting an improved system, or making improvements to pat itself (JPat, hehe, bring it on). 

I do all my development with pat now and actually find few situations that I can't get around.  Nested loops is probably the hardest thing to do in pat but I have techniques to do these that only take a few lines of code and a few templates.

Re: bye bye patTemplate

Posted: Tue Jul 11, 2006 11:25 pm
by Vimes
I was talking to somebody else the other day who was using some of the inbuilt functionality of patT to do some of the logic, granted not with a lot of luck, although I suspect he's cracked it by now. It surprised me because I take a probably simplistic approach to how I use them: they're used strictly for output, no logic, no loops, nothing.

My main reason for using them was to help my clients. Virtually all of them wanted to edit the layout in one form or another, so all I do is normally to an addRows with most of the output in just the one variable. Obviously there are times when you need to output rows of stuff, but largely that's all I do. Let's be honest, I'm the developer here, not them, and it doesn't seem fair to ask them to learn patT just so's they can move a little stuff around.

Perhaps I am being a little simplistic, but I love patT and how they work. It's really easy once you get your head around it, almost without fail my output now is doing using them even for the simplest pages.

It never fails to surprise me that we work so hard to remove the logic from the output, then bu**er it all up by putting logic in anyway.

Maybe I'm just being thick.

Re: bye bye patTemplate

Posted: Tue Jul 11, 2006 11:38 pm
by masterchief
Vimes, can you explain a little more.  I suspect you are not setting things up correct and that's why it seems difficult.

Re: bye bye patTemplate

Posted: Tue Jul 11, 2006 11:42 pm
by Vimes
On the contrary, it works a treat for me :) I was just commenting on how I don't understand when folks try to do logic in patT, it seems to defeat the object.

Re: bye bye patTemplate

Posted: Wed Jul 12, 2006 2:13 pm
by Alejo
Initially I had a very difficult time trying to figure out how to use patTemplate.

First I was trying to create a directory with sections and categories within the sections and it was not easy, but I found a way around it while still using patT and not sending html to patT variables. Thanks to encouragement from Vimes and Phil I have now developed a component using 100% patT (in the frontend) and it makes life a lot easier.

I hope to release my component soon!

Re: bye bye patTemplate

Posted: Wed Jul 12, 2006 5:05 pm
by dynedain
Nested loops and logic in templates is a nightmare. For example, I develop a portfolio component that we roll out for most of our clients. Now while most of our clients have similar needs for the portfolio, the end display functionality is often very different. I try to solve this using patTemplate, so that I only need to develop a template for each of my clients to handle the differences. The catch is that every time I find myself having to rewrite my component's functionality because I can't do things just in the template. Like looping through an array with a conditional, and then looping through the same array again with a different conditional in another portion of the template. Providing the template with multiple copies of the array is redundant, especially when I don't know how many times I'll need it untill I develop the template.

Another thing that really bugs me is using PHP in a template. It works, but it operates before the {PATVALUES} replacements, which makes it useless in trying to do loops or other basic, but very usefull things that are based on the values of the patTemplate variables.


Overall I'm finding patTemplate to be somewhat usefull, definitely more robust that the custom template system I was beginning to use when I switched, but there are many things that are very difficult, or require modifying your extension instead of just modifying the template. I don't have experience with other templating systems, so I'm not sure how it compares.

Maybee I'm just going about using patTemplate in my components the wrong way, but documentation/tutorials are severely lacking.

Re: bye bye patTemplate

Posted: Wed Jul 12, 2006 7:07 pm
by mmx
Vimes wrote: On the contrary, it works a treat for me :) I was just commenting on how I don't understand when folks try to do logic in patT, it seems to defeat the object.

Some Joomla-specific tutorials will most likely solve the majority of problems discussed here. There appears to be a lot of misunderstanding about how it should be used.

ianmac... I spotted a few posts on a German site a few weeks ago. I believe that the author is working on a new project which I'm assuming to be a PHP n-tier framework or portal of some sort based on the topic matter in the thread.

Re: bye bye patTemplate

Posted: Wed Jul 12, 2006 7:36 pm
by ianmac
I don't recall the nuances of my frustration...

But what I was trying to do was to write a HTML template library in patTemplate so that I could use it instead of the mosHTML class, since it seemed like this ought to be the way to do it...

At the start I was using the JDesigner component as an architecture model for my component.

I couldn't find a straightforward way to build this library.  Could just be me though...  this is a hobby, not a profession for me :)

Ian

Re: bye bye patTemplate

Posted: Wed Jul 12, 2006 7:41 pm
by ianmac
Also,

did anybody ever find a way to output { or } in a template?  I seem to recall someone having trouble with this, and it seemed to me to be a bug with patTemplate...

This shouldn't be a difficult thing - a simple escape character SHOULD do the trick...

Ian

Re: bye bye patTemplate

Posted: Wed Jul 12, 2006 10:41 pm
by dynedain
Vimes wrote: On the contrary, it works a treat for me :) I was just commenting on how I don't understand when folks try to do logic in patT, it seems to defeat the object.
There's good reasons to do logic in the template. Specifically display logic instead of functionality logic. The odd/even condition used to make alternating row colors in a table or list is a good example of display logic. Another example of display logic would be highlighting an item in a list because it is the "active" item, or display certain variables if certain other nested variables from a display loop are set to certain values.

Re: bye bye patTemplate

Posted: Thu Jul 13, 2006 12:07 am
by akede
ianmac wrote: Also,

did anybody ever find a way to output { or } in a template?  I seem to recall someone having trouble with this, and it seemed to me to be a bug with patTemplate...

This shouldn't be a difficult thing - a simple escape character SHOULD do the trick...

Ian
This could be a solution - Alex

http://forum.php-tools.net/index.php?t= ... 3b1a04e798

Re: bye bye patTemplate

Posted: Sat Jul 15, 2006 10:20 pm
by ianmac
Thanks for writing Andrew...

You're continued use provides me with reassurance that perhaps this will be a good solution.  I suppose the core team will have to worry about maintenance though - it looks like development has stopped.  The reason I raised the question was that I was surprised at first that all the component were being refactored, yet none were using patTemplate.  Hard to push something that isn't being used in the core...  ;(

It was mentioned before that performance took a real hit with patTemplate...  is there a solution in the works for this?

Anyway, I will give it another shot and see where I get.

Ian

Re: bye bye patTemplate

Posted: Thu Aug 10, 2006 4:48 pm
by bigwang
Stupid question, what is pat Tempalte?

Re: bye bye patTemplate

Posted: Thu Aug 10, 2006 7:35 pm
by louis.landry
ianmac wrote: Thanks for writing Andrew...

You're continued use provides me with reassurance that perhaps this will be a good solution.  I suppose the core team will have to worry about maintenance though - it looks like development has stopped.  The reason I raised the question was that I was surprised at first that all the component were being refactored, yet none were using patTemplate.  Hard to push something that isn't being used in the core...  ;(

It was mentioned before that performance took a real hit with patTemplate...  is there a solution in the works for this?

Anyway, I will give it another shot and see where I get.

Ian
patTemplate does have some considerable weaknesses with regards to performance.  My personal opinion is that we need to utilize a system which uses the syntax/API of patTemplate or something very similar because I consider it to be a great example of presentation logic / business logic separation, it uses XML syntax which means with a proper DTD it could pass validation and can render to some degree in a WYSIWYG editor, it also allows for a very finite set of logic which gently forces the separation. 

We need those benefits with appropriate performance gains... how we get to that end I'm not sure yet but it will definitely be a part of the planning process for future versions.

I'm not sure we need to be pushing patTemplate's use to the developer community.  It is an available tool, but I wouldn't go so far as to say it is even necessarily recommended... its just available :)

Louis

PS. regarding "what is patTemplate": http://www.google.com/search?q=patTemplate

Re: bye bye patTemplate

Posted: Thu Aug 10, 2006 8:24 pm
by mmx
louis.landry wrote:
ianmac wrote: Thanks for writing Andrew...

You're continued use provides me with reassurance that perhaps this will be a good solution.  I suppose the core team will have to worry about maintenance though - it looks like development has stopped.  The reason I raised the question was that I was surprised at first that all the component were being refactored, yet none were using patTemplate.  Hard to push something that isn't being used in the core...  ;(

It was mentioned before that performance took a real hit with patTemplate...  is there a solution in the works for this?

Anyway, I will give it another shot and see where I get.

Ian
patTemplate does have some considerable weaknesses with regards to performance.  My personal opinion is that we need to utilize a system which uses the syntax/API of patTemplate or something very similar because I consider it to be a great example of presentation logic / business logic separation, it uses XML syntax which means with a proper DTD it could pass validation and can render to some degree in a WYSIWYG editor, it also allows for a very finite set of logic which gently forces the separation. 

We need those benefits with appropriate performance gains... how we get to that end I'm not sure yet but it will definitely be a part of the planning process for future versions.

I'm not sure we need to be pushing patTemplate's use to the developer community.  It is an available tool, but I wouldn't go so far as to say it is even necessarily recommended... its just available :)

Louis

PS. regarding "what is patTemplate": http://www.google.com/search?q=patTemplate
Louis... there are a few lightweight template parser classes based on the Decorator Pattern that are used on some of the MVC frameworks. There include the template classes for WACT, Mojavi, and CodeIgniter. The tokens used in CodeIgniter's template parser classs are similar to patTemplate. However, all of these template were designed to be lightweight to achieve high performance and lack support for loops, conditionals, etc. I did some testing on CodeIgniter earlier to compare the cache speed differences between their standard PHP views and their optional template parser views and found the speed hit to be negligible.

Re: bye bye patTemplate

Posted: Thu Aug 10, 2006 9:15 pm
by louis.landry
Excellent ... as soon as i get a little free time i'll delve into the options and see waht we can come up with.  I personally am thinking it may be worth taking ideas / concepts from lseveral different options and building our own templating engine based on the best features of each of these.  Would love to work together with you and whomever else to nail down a solid requirement and go after a proof of concept sometime in teh future.

As always your insight is appreciated :)

Louis

Re: bye bye patTemplate

Posted: Fri Aug 11, 2006 7:13 am
by mmx
Louis... I'm not sure if you have looked at this one. It uses a simple tag syntax that renders cleanly in a WYSIWYG editor. This is a single class with 6 methods and 5 properties. It has a plugin architecture for extensibility, loops, conditionals, and support for databases. I have not used this myself,  but it looks interesting. If you want to play with this with a MVC architecture, there is a code snippet on the CodeIgniter wiki that installs TinyButStrong as a plugin template engine.

http://www.tinybutstrong.com/

Re: bye bye patTemplate

Posted: Fri Aug 11, 2006 4:29 pm
by Asphyx
Louis - would it not be better to create an API that we could plug different rendering systems into?

almost like the driver system for cross DB support?

I was thinking of output as a sort of CSS file of code where you define tags as a subroutine and call to those tags in the same way you do with CSS.

If joomla can provide that type of general hook it should be possible to create a driver file for PTTemps and Shorty and any other renderer you could think of.

But I admit that is a bit beyond my scope and not sure if that would even be possible....

Re: bye bye patTemplate

Posted: Fri Aug 11, 2006 6:42 pm
by louis.landry
@mmx: Thanks for the pointer, I will certainly have a look at it.  I really like the idea of having an XML syntax for a templating language because it enables really fun things like xml transformations to achieve lots and lots of different things.

@Asphyx:  Ultimately yes, you are spot on, what I would like to do is evaluate the different templating systems out there... take notes on the different APIs... then come to a consensus on what WE need in a rendering engine API.  Once we settle on a common API for the Joomla! framework, we abstract the API such that templating engines are pluggable much like the driver system for JDatabase as you mentioned.  As part of this exercise though, I would like to implement a core rendering engine that utilizes what we consider to be the best aspects of the different engines out there.

Your idea of a tag library of defined templates is in line with how I would like our final MVCR system to work, but I will admit that I haven't given it enough thought yet to determine exactly how I think it should behave.

Louis

Re: bye bye patTemplate

Posted: Fri Aug 11, 2006 9:06 pm
by Asphyx
ok Louis I have to admit I cheated...
Johan explained all that to me at some point in the definition of MVCR when I asked him about it in another topic! I just took the API concept and tried to visualize how it would work which is where I got the tags from! LOL

I agree you will have to supply a rendering engine (either custom or one you pick) just so that the output is set in the default. But whatever is chosen or created can then at least be built upon or even replaced by someone who needs someone else...
This is what makes the Application framework of the 1.5 track so great!

Re: bye bye patTemplate

Posted: Mon Aug 14, 2006 4:39 am
by ianmac
masterchief wrote: Hi Ian

What are the problems?  I can probably give you some help - or if nothing else we know what problems you have faced to know what to look for in selecting an improved system, or making improvements to pat itself (JPat, hehe, bring it on). 

I do all my development with pat now and actually find few situations that I can't get around.  Nested loops is probably the hardest thing to do in pat but I have techniques to do these that only take a few lines of code and a few templates.
Andrew,

Here is the issue I have faced before and am facing again.  I would like to be able to link a template using variables passed from the linking template.

So for example, I could have something like:








I realize I could to this by simply specifying varscope for the linked template, but I would like to be able to call this from different templates without having to add extra PHP code.

Is this possible with patTemplate?

Ian

Re: bye bye patTemplate

Posted: Fri Aug 18, 2006 10:12 am
by progster
A further note on usage of patTemplate: joomlaboard 1.2 will use it heavilly, so don't remove it! It's our new templating system and so far it' working good.

How big is the performance hit mentioned earlier?

Re: bye bye patTemplate

Posted: Sun Aug 27, 2006 9:44 am
by globule
progster wrote: A further note on usage of patTemplate: joomlaboard 1.2 will use it heavilly, so don't remove it! It's our new templating system and so far it' working good.

How big is the performance hit mentioned earlier?
It is a wonderfull idea!
I love this component, the only "full Joomla!" forum. But the actual version is to much "iterative", as we discussed on your forum (globule=lolo on tsmf). This will be a really good example of using pT, which I don't really know.

We translated some tutos from J! Wiki (hello_world, patTemplate, toolbar...). Each describes one way of writing J! code but there is no tuto compiling all of them... is it possible such a tuto appear one day?

Re: bye bye patTemplate

Posted: Wed Sep 13, 2006 9:35 am
by kmekc
I've already used some Template Engines.

First something like Sigma, IT, IT[X] from PEAR-Library. But because they use Pattern-Search and does'nt have built-in caching there performance was not very good.

Then i found Smarty. An engine that precompiles the template to some php and caches the compiled template. Seems that phptal is not very different but on my own i would prefer smarty as it seems easier to me and i already use this template engine in some other projects.

Maybe there will be a probability to switch the template engine? :)

But i will look forward till Joomla uses phptal to render the page template.

Re: bye bye patTemplate

Posted: Tue Oct 03, 2006 10:01 am
by absalom
I'm currently investigating TBS as a way of migitating the perfomance hits if we ever get to semantic J! (perhaps through semantics as sub-blocks).

If MMX and I come to the same place with the same ideas, we must be onto something  8)

Re: bye bye patTemplate

Posted: Tue Oct 03, 2006 7:19 pm
by mmx
absalom wrote: I'm currently investigating TBS as a way of migitating the perfomance hits if we ever get to semantic J! (perhaps through semantics as sub-blocks).

If MMX and I come to the same place with the same ideas, we must be onto something  8)
absalom... I followed Louis' advice and looked a bit further. I'm currently experimenting with the Template Parser class from the CodeIgniter framework. The general idea is to minimize the complexity of the template parser by utilizing the controller code and helpers to achieve better performance over a full-blown template engine. I'm playing with this in CodeIgniter and will attempt to adapt the general approach to Joomla! for a project I'm working on. The html for a sample View shown in their user guide (copyright 2006, pMachine, Inc.) is shown below.

Code: Select all

<html>
<head>
<title>{blog_title}</title>
</head>
<body>

<h3>{blog_heading}</h3>

{blog_entries}
<h5>{title}</h5>
<p>{body}</p>
{/blog_entries}
</body>
</html>
The above uses pseudo variables, so it should look familiar.

Their controller code for the view is below.

Code: Select all

$query = $this->db->query("SELECT * FROM blog");

$this->load->library('parser');

$data = array(
              'blog_title'   => 'My Blog Title',
              'blog_heading' => 'My Blog Heading',
              'blog_entries' => $query->result_array()
            );

$this->parser->parse('blog_template', $data);
The documentation in the CodeIgniter user guide is easy to follow. It might be best to experiment with this using the basic CodeIgniter distribution so you can learn how view fragments work in their view scheme. View fragments are equivalent to blocks.

Keep in mind that this is not a full-blown template engine. Things like loops and conditionals are handled by the controller and appear as pseudo variables in the view.

Re: bye bye patTemplate

Posted: Wed Oct 04, 2006 1:12 am
by absalom
It seems we can also learn from our competition.  MODx: http://modxcms.com/ also uses TBS, so I'm looking through how they've implemented it and what we can learn from it. Walking through the source code now..

And then there's this on how Modx construct: http://modxcms.com/modx-tags.html