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.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 02:09:29
Script start
Timing: Jan 18 2025 02:09:29
Module start 'layout'
Timing: Jan 18 2025 02:09:29
Module start 'content'
Timing: Jan 18 2025 02:09:30
Module end 'content'
Timing: Jan 18 2025 02:09:30
Script end

Main resources:

Total runtime0.7467 sec
Peak memory usage4,096.0000 KB
Database Queries80

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0051 588.9219152.6094
Module start 'layout' 0.00510.0029 741.531339.4219
Module start 'content' 0.00800.7371 780.9531728.4766
Module end 'content' 0.74510.0015 1,509.429720.1953
Script end 0.7466  1,529.6250 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.5267160.0002
Check MTime0.00150.1970160.0001
Mysql Total
Database connection0.00070.088410.0007
Mysqli_queries0.671289.8943800.0084
Looping result0.00080.1134780.0000
Template Total0.715695.820.3578
Template load0.00210.278920.0010
Template processing0.713695.564520.3568
Template load and register function0.00010.019310.0001
states
state_id_array0.00130.176510.0013
state_identifier_array0.00080.108820.0004
Override
Cache load0.00190.2487470.0000
Sytem overhead
Fetch class attribute can translate value0.00100.130450.0002
Fetch class attribute name0.00130.1788110.0001
XML
Image XML parsing0.00170.221850.0003
class_abstraction
Instantiating content class attribute0.00000.0024110.0000
General
dbfile0.00230.3051300.0001
String conversion0.00000.001140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
2content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ol.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ol.tplEdit templateOverride template
1content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 34
 Number of unique templates used: 11

Time used to render debug report: 0.0001 secs