eZ Community » Forums » General » PHP support in templates
expandshrink

PHP support in templates

PHP support in templates

Monday 14 July 2003 10:10:57 am - 14 replies

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!

Modified on Monday 14 July 2003 10:15:19 am by Mark Overduin

Monday 14 July 2003 10: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

Monday 14 July 2003 10:24:01 am

Thanx! This will probably help me...

Monday 14 July 2003 12:17:50 pm

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??

Monday 14 July 2003 12:29:44 pm

Afaik not. Anyone else knows better?

Link on template operators:
http://ez.no/developer/ez_publish...ent/kernel/custom_template_operators

Karsten

Monday 14 July 2003 12:55:27 pm

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

Monday 14 July 2003 1:17:41 pm

More info in the forum:
http://ez.no/developer/ez_publish...lp_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. happy.gif Emoticon

Monday 14 July 2003 4:16:26 pm

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. happy.gif Emoticon

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

Modified on Monday 14 July 2003 4:17:26 pm by Alex Jones

Monday 14 July 2003 9: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

Monday 14 July 2003 10:50:43 pm

Woohoo! That would make life much easier.

Tuesday 15 July 2003 10: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...cks/including_php_files_in_templates

Modified on Tuesday 15 July 2003 3:09:51 pm by Mark Overduin

Tuesday 15 July 2003 11:28:19 am

Hi Mark,

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

Karsten

Tuesday 15 July 2003 11:38:28 am

Right away... where can I find it?

Tuesday 15 July 2003 11:41:10 am

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

Karsten

Tuesday 15 July 2003 3:05:52 pm

Check the link for a solution:

http://ez.no/developer/ez_publish...cks/including_php_files_in_templates

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from