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.

eZ debug

Timing: Jan 17 2025 23:52:07
Script start
Timing: Jan 17 2025 23:52:07
Module start 'content'
Timing: Jan 17 2025 23:52:08
Module end 'content'
Timing: Jan 17 2025 23:52:08
Script end

Main resources:

Total runtime1.2851 sec
Peak memory usage4,096.0000 KB
Database Queries217

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0067 587.5859180.8594
Module start 'content' 0.00671.0211 768.4453727.6250
Module end 'content' 1.02780.2572 1,496.0703340.4531
Script end 1.2850  1,836.5234 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00430.3315210.0002
Check MTime0.00150.1182210.0001
Mysql Total
Database connection0.00070.055610.0007
Mysqli_queries1.179091.74352170.0054
Looping result0.00280.21512150.0000
Template Total1.248497.120.6242
Template load0.00240.182920.0012
Template processing1.246196.965820.6230
Template load and register function0.00030.019510.0003
states
state_id_array0.00230.178010.0023
state_identifier_array0.00210.164320.0011
Override
Cache load0.00200.1521470.0000
Sytem overhead
Fetch class attribute can translate value0.00570.441260.0009
Fetch class attribute name0.00180.1420110.0002
XML
Image XML parsing0.00300.236660.0005
class_abstraction
Instantiating content class attribute0.00000.0017110.0000
General
dbfile0.00260.2031410.0001
String conversion0.00000.000530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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