4images Forum & Community

4images Help / Hilfe => FAQ, Tips => Topic started by: Chris on February 23, 2003, 10:02:35 PM

Title: How can I include another PHP file in the templates?
Post by: Chris on February 23, 2003, 10:02:35 PM
Open the 4images html template where you would like to include your PHP file and include it like this:
Code: [Select]
<?php 
include($_SERVER['DOCUMENT_ROOT']."/relative/path/to/my/include.php"); 
?>
Next, open includes/constants.php and change
Code: [Select]
// Allow execution of PHP code in templates
define('EXEC_PHP_CODE', 0);
to this
Code: [Select]
// Allow execution of PHP code in templates
define('EXEC_PHP_CODE', 1);

PLEASE be sure to read this FAQ forum topic: http://www.4homepages.de/forum/index.php?topic=3378
for information regarding some limitations and possible solutions for working with certain types of PHP scripts.

[UPDATE]
If you are using relative path ./ inbetween the templates, then be advised, that php will look for files in includes/ directory and not 4images root!
i.e. if used
Code: [Select]
<?php
include("./somephpfile.php");
?>
the somephpfile.php must be placed in includes/ folder.
Title: Re: How can I include another PHP file in the templates?
Post by: khan on July 31, 2005, 10:51:49 PM
HI
I Did every thing described above but php including does not works in my templates.
at the place where i included the php file its display blank area and does not Showing the data of the included Php file.
Title: Re: How can I include another PHP file in the templates?
Post by: V@no on July 31, 2005, 10:58:50 PM
and what does it show u when u try open that file directly in the browser as a web page?
Title: Re: How can I include another PHP file in the templates?
Post by: khan on August 03, 2005, 08:57:39 PM
Hi
When i open it in browser it display every thing inside the files. but when i include it in 4images it displays blank white area.
Title: Re: How can I include another PHP file in the templates?
Post by: V@no on August 04, 2005, 01:03:01 AM
sounds like a conflict between 4images and your script.
Title: Re: How can I include another PHP file in the templates?
Post by: tatty on February 23, 2006, 02:59:13 AM
Hello.
For me it's not working too :(
I've done what told in the post, but when I click "save changes" it shows me a blank space. I go to the gallery page and no changes were done! I mean, I add the php include but no changes happen.

Any suggestion? Thanks!
Title: Re: How can I include another PHP file in the templates?
Post by: V@no on February 23, 2006, 03:23:04 AM
Did you apply all the bug fixes? I guess you didnt.
Title: Re: How can I include another PHP file in the templates?
Post by: killerwhale65 on March 10, 2006, 12:41:10 PM
what if i want to include a php file on the frontpage (index.php)? How can i do that?

thanks!
Title: Re: How can I include another PHP file in the templates?
Post by: mawenzi on March 10, 2006, 01:51:27 PM
...How can i do that? ...


Exactly the same as here (http://www.4homepages.de/forum/index.php?topic=4295.msg17676#msg17676) described !
Title: Re: How can I include another PHP file in the templates?
Post by: killerwhale65 on March 10, 2006, 01:54:23 PM
and what is the html template i should use? I dont find an index.html ...
Title: Re: How can I include another PHP file in the templates?
Post by: V@no on March 10, 2006, 01:56:51 PM
home.html
Title: Re: How can I include another PHP file in the templates?
Post by: mawenzi on March 10, 2006, 01:59:20 PM
as you can see on top of index.php
Code: [Select]
$main_template = 'home';

the template for index.php ist home.html ...  :!:
Title: Re: How can I include another PHP file in the templates?
Post by: colorssky on October 09, 2006, 11:03:23 PM
I tried to add the follwing, because I am using poll script

______________
<?php
include($_SERVER['DOCUMENT_ROOT']."/home/takfeed/public_html/poll/booth.php'");
display_booth(1); ?>
_______________

but I got this error

Warning: Unknown(/home/takfeed/public_html/home/takfeed/public_html/poll/booth.php'): failed to open stream: No such file or directory in /home/takfeed/public_html/shop/includes/template.php(101) : eval()'d code on line 84

Warning: Unknown(/home/takfeed/public_html/home/takfeed/public_html/poll/booth.php'): failed to open stream: No such file or directory in /home/takfeed/public_html/shop/includes/template.php(101) : eval()'d code on line 84

Warning: (null)() [function.include]: Failed opening '/home/takfeed/public_html/home/takfeed/public_html/poll/booth.php'' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/takfeed/public_html/shop/includes/template.php(101) : eval()'d code on line 84

Fatal error: Call to undefined function: display_booth() in /home/takfeed/public_html/shop/includes/template.php(101) : eval()'d code on line 85

Title: Re: How can I include another PHP file in the templates?
Post by: iraklis on January 05, 2007, 03:10:56 PM
Î've problems too.

Parse error: parse error, unexpected '/' in /dev/httpdocs/includes/template.php(133) : eval()'d code on line 372

Anybody an idea?
Title: Re: How can I include another PHP file in the templates?
Post by: KurtW on January 06, 2007, 02:52:22 PM
Hi colorssky,

Code: [Select]
<?php 
include($_SERVER['DOCUMENT_ROOT']."/poll/booth.php"); 
?>

To iraklis

To mutch / in your code.



cu
Kurt
Title: Re: How can I include another PHP file in the templates?
Post by: osnapicture on February 21, 2007, 11:10:01 PM
is there anybody who could help me? i tried everything but i can't include a php file. maybe i used the wrong directory.
i would like to include the index page of a guestbook which you can find in www.mydomain.com/templates/default/guestbook/index.php
what would be the right code to include this into an html-template site?
Title: Re: How can I include another PHP file in the templates?
Post by: shaiba81 on March 29, 2007, 05:46:41 AM
Exactly the same as here described !
Title: Re: How can I include another PHP file in the templates?
Post by: CeJay on March 29, 2007, 06:59:41 AM
you can not include a php file/page into a html page, if your html page is a template for 4images then follow directions again.
Otherwise if you have a home page that is a html page you can not call a php page into it.
Title: Re: How can I include another PHP file in the templates?
Post by: Flo2005 on April 01, 2007, 02:07:07 PM
WeŽll I think if you want to integrate a complete new php-file you have to do:

edit: all files

categories.php
details.php
index.php
lightbox.php
member.php
postcards.php
register.php
search.php
top.php

search for this:
Code: [Select]
require(ROOT_PATH.'includes/sessions.php');
and add this after:
Code: [Select]
include(ROOT_PATH.'my_new_phpfile.php');
Upload your new phpfile in the root of your 4images installation.

There was a topic where chris has written how you can call this file in your template html-files
Title: Re: How can I include another PHP file in the templates?
Post by: adrian.gab on July 10, 2007, 02:38:40 PM
Is there a special trick to getting the 4images tags (e.g. {template_url} {if random_image} {site_name}) to work within an include file called from a template file e.g. home.html, details.html?

See my post here for more info:

http://www.4homepages.de/forum/index.php?topic=18003.msg95825 (http://www.4homepages.de/forum/index.php?topic=18003.msg95825)
Title: Re: How can I include another PHP file in the templates?
Post by: mawenzi on July 10, 2007, 03:06:33 PM
... there is no trick ...
... the tags works only in the templates by their php-files in which they was generated ...
... e.g. ...
... tags in home.html are generated in index.php ...
... tags in details.html are generated in details.php ...
... a.s.o. ...
... but some tags are generated in functions.php ...
... to use the tags in templates you must call the pertinent php-file in the browser, not the template-file ...
... so ...
... if you want to use tags, you must edit a php-file which generated these tags and call the template ...
... have a look in details.php ... and ... details.html to see how it works in 4images ...
Title: Re: How can I include another PHP file in the templates?
Post by: adrian.gab on July 10, 2007, 04:20:43 PM
ok, i think i sort of understand. the tags will only work when a template file is read from a php file e.g.

$site_template->print_template($site_template->parse_template($main_template));

am i understanding this right? that is a shame, i wish it would just parse / read the tags from include files called from templates.

what if i want to call a template within a template?

this is what i am trying to achieve. the templates are labourious to update. if i make a change i generally have to update all of them. since nearly all of the templates are indentical except for the contents of one table cell, i would like the non changing content to be one file and the changing content as another file. this way if i update a header or something like that, then i don't have to edit all of the templates.



Title: Re: How can I include another PHP file in the templates?
Post by: webmaster73 on July 27, 2007, 11:29:42 PM
I have long long been looking .......  I wish I searched here before trying to figure out this alone.

Title: Re: How can I include another PHP file in the templates?
Post by: webmaster73 on September 28, 2007, 02:20:54 PM
Open the 4images html template where you would like to include your PHP file and include it like this:
Code: [Select]
<?php 
include($_SERVER['DOCUMENT_ROOT']."/relative/path/to/my/include.php"); 
?>


works like a breeze. so easy. thank you very much.
Title: Re: How can I include another PHP file in the templates?
Post by: thunderstrike on September 28, 2007, 08:34:04 PM
If use in 4images -

replace:

Quote
include($_SERVER['DOCUMENT_ROOT']."/relative/path/to/my/include.php");

for:

Code: [Select]
include($HTTP_SERVER_VARS['DOCUMENT_ROOT']."/relative/path/to/my/include.php");