Include .php file in block body

deepM - May 25, 2009 - 14:18

What would be proper way to include some php files into block body. Currently i created block and added code in block body like
include "tab.php";
but i had to put this file into www\mysite\includes so it can be included, wanted to put it into theme directory but didnt know how to make block get it from mytheme. What do you suggest?

thanx

include in block body

mwease - October 11, 2009 - 15:50

i have had no problem with including any file from any directory as long as i specify the path.

what works for me is (this is not a real directory on my system):

include "sites/all/themes/mytheme/tab.php";

i can't imagine why nobody has responded to you before this, but i've had the same experience many times. i'm sure you've worked around it or figured it out yourself.

include in block

mwease - October 14, 2009 - 16:56

your include works when you put the file in your include directory. that's the norm. i'm not certain if it's a better way or a good way, but you can also do it two other ways:

1) relative path - first directory in path is the first directory under your "home" directory for your site in which your file is located. i put several include files in my site's (on a server-hence the normal slashes) "files" directory. drupal says 'sites/all/files' is that directory. therefore, if you put your include file there, you can include it by the relative-path method of include 'sites/all/files/tab.php'; i have a modification to the bluemarine theme/template, so, if i wanted it there and i wanted to include it somewhere, my relative-path include statement would be

include 'sites/all/themes/bluemarine/tlp_bluemarine/tab.php';

2) absolute path - specify the entire path to the file. using the same example as for 1) above:

include 'http://www.mysite.com/sites/all/themes/bluemarine/tlp_bluemarine/tab.php';

the absolute path will have to be changed everywhere I use it if I move my site out of the normal "www.mysite.com" url. the relative path will have to be changed everywhere i use it if I change my directory structure somewhere between "sites" and "tlp_bluemarine" or rename any of them.

see www.drupal.org/project/pathologic

thanx on your info. seems

deepM - October 19, 2009 - 17:06

thanx on your info. seems that when i made include "something.php" without "include/" i guessed that the root for include was this and it isnt, it just searches for there aswell. :-)

 
 

Drupal is a registered trademark of Dries Buytaert.