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.