Forums / Developer / Template system

Template system

Author Message

Sao Tavi

Thursday 30 June 2011 8:18:06 am

What is the advantage of the current template system syntax over plain PHP syntax? Are there things that the template system syntax can do and PHP cannot?

I cannot find the logic in a/any template system that has a syntax of it's own. In the last few days I had to put so many PHP functions in the template system syntax, that I wonder why there even is such a syntax.

If we just want to add to the complexity of it, I agree this is a strategic move, but we are getting farther and farther away from the easy point of view. And the less easy, the less people around.

I must say that I looked at Rasmus Lerdorf's speech in London and he pointed out pretty clearly: PHP won because of it's simplicity. Because one can do in PHP a lot without any prior knowledge of PHP.

 

Please prove me that I am wrong and that the separate language for the template system is needed.

André R.

Thursday 30 June 2011 9:48:30 am

Template system are to enforce separation between presentation and business logic.
So might be that your are violating that separation, and that is fine for your own project and there are no one stopping you from doing that.

But think large projects with ten-twenty people or more involved and you quickly see issues popping up when people with different skills all the way from designers to programmers create templates to present some data/content. Read up on concepts around MVC and you'll quickly realize that PHP is not a template language for the V in MVC despite numerous claims from some of the core PHP guys that only deal with C and Zend Engine all day and thus views user land code as template code.

Now you hopefully understand why a system like eZ Publish has to have this kind of separation by default. We plan to allow developers to use php templates in the future when we most likely switch to eZ/Zeta Components Template Engine, but it will never be the default way for the view layer of the system.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Sao Tavi

Thursday 30 June 2011 10:27:24 am

Thank you for the response, Andre

I do understand why a template system IS needed and I never mix processing with output in my projects (at least when I am not requested to build websites on platforms like OScommerce).

My only problem is the syntax, as it is independent from PHP and is having elements from a lot of different programming languages I've seen. Learning another syntax it is not hard, but facing the lack of so many basic functions is. Also, it is not so readable ( at least, from my point of view, $counter++ is a lot easier to read than {set $counter = $counter|sum(1)} ), I can't find a syntax highlighter for notepad++ (I believe a smarty syntax highlighter should do), casting can be a pain, assigning elements to vectors in a non increasing order can also be a pain.

So, my main problem is the functionality. Isn't there any function like php('phpFunctionName', $var1, $var2, $var3, ...) ?

Carlos Revillo

Thursday 30 June 2011 11:03:18 am

Two hints here.

  1. some part of the php functions can be easily used in templates as long as those functions works with a only parameter and return by value and not by reference. have a look at the doc page.
  2. There's also a contrib trying to help on that. maybe you can take a loot at. wrap_operator 

Other than that, i'm fully agree with André here.

Sao Tavi

Thursday 30 June 2011 11:20:06 am

Great, thanks, I did not know about those ini settings.

Peter Keung

Thursday 30 June 2011 11:43:47 am

Regarding syntax highlighting for eZ Publish templates, there's a nice Eclipse plugin:

http://smile-ez-plugin.sourceforge.net/

http://www.mugo.ca
Mugo Web, eZ Partner in Vancouver, Canada

Daniel A. Øien

Thursday 30 June 2011 11:27:10 pm

"

Also, it is not so readable ( at least, from my point of view, $counter++ is a lot easier to read than {set $counter = $counter|sum(1)} )

"

{set $counter = $counter|inc()} is more natural to use, but of course nearly as verbose since there aren't any shorthand assignment operators in the template language.

I mention this because the template language has quite a lot of basic functions if you wade through the documentation long enough :)

Daniel A. Øien
Open Concept SA, Norway
Web: http://openconcept.no/
In English: http://openconcept.no/eng

Sao Tavi

Tuesday 05 July 2011 6:53:26 am

Thank you, Peter, for the hint about the Smile project.

I do have some issues installing it as the documentation is out of date.

 

Daniel, thank, I did not know about that function, but, as you said, it does not reduce the code size or improve readability too much.