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