Forums / Setup & design / Embedding PHP within templates

Embedding PHP within templates

Author Message

Andy Woods

Monday 04 April 2011 11:07:23 am

Hi,

How easy is it to embed PHP within template files?

Can you give me any step-by-step examples of how to do it please?

Thanks,

Andy

Nicolas Pastorino

Monday 04 April 2011 11:43:51 am

Hi Andy,

It is not possible directly. The way is to extend the template engine/language through :

  • A fetch function : http://share.ez.no/learn/ez-publish/understanding-and-developing-fetch-functions
  • A template operator : http://share.ez.no/learn/ez-publish/an-introduction-to-developing-ez-publish-extensions/(page)/10
  • A mirrored PHP function : http://share.ez.no/forums/developer/url-encode#comment48350

Cheers,

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Marko Žmak

Monday 04 April 2011 2:01:57 pm

Also, the wrap operator extension could be usefull:

  • http://projects.ez.no/wrap_operator

It's a wrapper that allows you to use any PHP function inside the eZP templates.

Of course, you must use this wisely and with caution.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Andy Woods

Tuesday 05 April 2011 12:06:23 am

Hi Marko,

Thank you for your help - can you tell me what I need to be careful of when using PHP please?

Andy

Marko Žmak

Tuesday 05 April 2011 12:33:05 am

"

Hi Marko,

Thank you for your help - can you tell me what I need to be careful of when using PHP please?

Andy

"

Well you'll have to be caerfull about pretty much the same thing when coding in pure PHP. Performance and security issues mostly. To make a list of it would be out of the scope for this forum.

The main "problem" is that when you use the eZP template language, the eZP itself takes care of many performance and security issues, and if you use much PHP within templates you lose this layer of protection.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

eZ debug

Timing: Jan 17 2025 22:00:05
Script start
Timing: Jan 17 2025 22:00:05
Module start 'content'
Timing: Jan 17 2025 22:00:05
Module end 'content'
Timing: Jan 17 2025 22:00:05
Script end

Main resources:

Total runtime0.1682 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0066 587.7266180.8438
Module start 'content' 0.00660.0063 768.570398.0859
Module end 'content' 0.01290.1552 866.6563525.7891
Script end 0.1681  1,392.4453 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00372.2293200.0002
Check MTime0.00140.8248200.0001
Mysql Total
Database connection0.00120.730610.0012
Mysqli_queries0.117369.74451410.0008
Looping result0.00150.89441390.0000
Template Total0.154792.010.1547
Template load0.00110.660010.0011
Template processing0.153591.277510.1535
Override
Cache load0.00080.466210.0008
Sytem overhead
Fetch class attribute can translate value0.00110.633210.0011
XML
Image XML parsing0.00030.165810.0003
General
dbfile0.00513.0492200.0003
String conversion0.00000.002830.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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0002 secs