PHP support in templates

Author Message

Mark Overduin

Monday 14 July 2003 1:10:57 am

Is there any way to use php in the templates?
I cannot use php codes in de .tpl files (probably because of .tpl extension). I tried to include a php file (simple hello world). The file is included, I see the text used in the .php file, but the php is not parsed at all.

I use this line to include the file:
{include uri="doesthiswork.php" name="bottom"}

Thanks!

Karsten Jennissen

Monday 14 July 2003 1:15:49 am

Hi Mark,

PHP is not supported in the templates (separation of code and layout). If you need some small specific PHP in the templates, you can write a template operator that does what you want. See docs -> developer -> extensions on how to write a template operator.

Karsten

Mark Overduin

Monday 14 July 2003 1:24:01 am

Thanx! This will probably help me...

Mark Overduin

Monday 14 July 2003 3:17:50 am

I was just thinking... I can't be the first to come up with this idea, so I figured someone has already written this, right?
I mean, many people want to be able to use php coding in their templates (or at least be able to include php code / .php files; which of course gets parsed).

ezPublish 3 is huge, it's extremely powerful, the possibilities are limitless (so it seems, sometimes), but it's not possible to use php or include .php files in templates by default??

Karsten Jennissen

Monday 14 July 2003 3:29:44 am

Afaik not. Anyone else knows better?

Link on template operators:
http://ez.no/developer/ez_publish_3/documentation/development/kernel/custom_template_operators

Karsten

Bård Farstad

Monday 14 July 2003 3:55:27 am

Mark, we don't support PHP in templates since we feel that would make it very tempting for people to use it. And we feel that it does not belong in the template language. That beeing said it's fairly quick to add this in a template operator. You could also make a template function which would execute PHP code directly in the template.

I would not recommend the latter though.

--bård

Documentation: http://ez.no/doc

Karsten Jennissen

Monday 14 July 2003 4:17:41 am

More info in the forum:
http://ez.no/developer/ez_publish_3/forum/developer/request_for_help_module_exampleexternal_php_script

I kinda found the original link in the docs on operators a bit confusing. Somebody should write up a short how-to for template operators. :-)

Alex Jones

Monday 14 July 2003 7:16:26 am

Mark, I thoroughly understand your point of view. Many of us with a moderate understanding of PHP who love the capabilities of eZ publish really wish we could just insert our PHP in the templates and be on our way. It would make life much easier and shorten the learning curve significantly. But then we would be missing a large reason for choosing eZ publish: separation of code and content. Ultimately if we have some code we feel is important enough to be used in our templates, then we should create a template operator to use. This will give us the power to re-use this code and keep it on the same level as the other available operators.

In addition to the re-usability and separation of code/content, creating operators provides an easy way to package our work and contribute it back to the community. I know I use a lot of community-contributed code in other software; I expect I will use some here as well. Hopefully I will be able to contribute an operator I've been working on (with the help of Paul Forsyth). It's small, but in many ways it is a payment for using this "free" product. :)

Suffice to say, while there is a steep learning curve at first, I think we would all do well to climb it and build our sites the right way.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Monday 14 July 2003 12:05:31 pm

Just noticed in an update to the 3.2 trunk that there is now a generic way to allow php operators to be accessible to the template without php coding. You need to enable the operator in an .ini file first but once done it seems you can use the operator as you would expect.

Haven't tried this out yet but it looks very promising for those of us who need to let an operator or two through at times.

paul

Alex Jones

Monday 14 July 2003 1:50:43 pm

Woohoo! That would make life much easier.

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Mark Overduin

Tuesday 15 July 2003 1:59:05 am

[edit]
I made a document for a possible solution, therefore I removed the text I put here, because it's not very efficient to have 'different solutions'.

Doc: http://ez.no/developer/ez_publish_3/documentation/customization/tips_tricks/including_php_files_in_templates

Karsten Jennissen

Tuesday 15 July 2003 2:28:19 am

Hi Mark,

could you add that to the documentation under Tips & Tricks? Thanks a lot!

Karsten

Mark Overduin

Tuesday 15 July 2003 2:38:28 am

Right away... where can I find it?

Karsten Jennissen

Tuesday 15 July 2003 2:41:10 am

You can just add a new page here:
http://ez.no/developer/ez_publish_3/documentation/customization/tips_tricks

Karsten

Mark Overduin

Tuesday 15 July 2003 6:05:52 am

Check the link for a solution:

http://ez.no/developer/ez_publish_3/documentation/customization/tips_tricks/including_php_files_in_templates

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 30 2025 21:39:55
Script start
Timing: Jan 30 2025 21:39:55
Module start 'layout'
Timing: Jan 30 2025 21:39:55
Module start 'content'
Timing: Jan 30 2025 21:39:55
Module end 'content'
Timing: Jan 30 2025 21:39:55
Script end

Main resources:

Total runtime0.0226 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0045 589.2578151.2109
Module start 'layout' 0.00460.0035 740.4688220.6719
Module start 'content' 0.00800.0125 961.14061,013.7422
Module end 'content' 0.02050.0020 1,974.882845.9922
Script end 0.0225  2,020.8750 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002711.8310140.0002
Check MTime0.00104.5844140.0001
Mysql Total
Database connection0.00073.139110.0007
Mysqli_queries0.002310.185930.0008
Looping result0.00000.034910.0000
Template Total0.00146.210.0014
Template load0.00114.710210.0011
Template processing0.00031.472810.0003
Override
Cache load0.00073.055510.0007
General
dbfile0.00031.138780.0000
String conversion0.00000.026440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs