eZ Community » Forums » Developer » Template system
expandshrink

Template system

Template system

Thursday 30 June 2011 5:18:06 pm - 7 replies

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.

Thursday 30 June 2011 6:48:30 pm

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.

Thursday 30 June 2011 7:27:24 pm

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, ...) ?

Thursday 30 June 2011 8:03:18 pm

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.

Thursday 30 June 2011 8:20:06 pm

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

Thursday 30 June 2011 8:43:47 pm

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

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

Friday 01 July 2011 8:27:10 am

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 happy.gif Emoticon

Tuesday 05 July 2011 3:53:26 pm

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.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from