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

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 01:15:08
Script start
Timing: Jan 18 2025 01:15:08
Module start 'layout'
Timing: Jan 18 2025 01:15:08
Module start 'content'
Timing: Jan 18 2025 01:15:09
Module end 'content'
Timing: Jan 18 2025 01:15:09
Script end

Main resources:

Total runtime1.0711 sec
Peak memory usage4,096.0000 KB
Database Queries65

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 589.0313152.6250
Module start 'layout' 0.00550.0036 741.656339.4688
Module start 'content' 0.00921.0606 781.1250607.5781
Module end 'content' 1.06970.0013 1,388.703112.1641
Script end 1.0710  1,400.8672 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.3091160.0002
Check MTime0.00140.1275160.0001
Mysql Total
Database connection0.00100.092510.0010
Mysqli_queries1.011594.4397650.0156
Looping result0.00070.0634630.0000
Template Total1.040097.120.5200
Template load0.00190.181920.0010
Template processing1.038096.909420.5190
Template load and register function0.00020.021110.0002
states
state_id_array0.00140.126910.0014
state_identifier_array0.00070.061620.0003
Override
Cache load0.00170.1578360.0000
Sytem overhead
Fetch class attribute can translate value0.00070.066430.0002
Fetch class attribute name0.00140.134970.0002
XML
Image XML parsing0.00120.109530.0004
class_abstraction
Instantiating content class attribute0.00000.002080.0000
General
dbfile0.00090.0846240.0000
String conversion0.00000.001040.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
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
2content/datatype/view/ezxmltags/ul.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ul.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: 23
 Number of unique templates used: 8

Time used to render debug report: 0.0001 secs