|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (11 bit)
Premium Member
Join Date: Dec 2003
Location: Boston, MA
Posts: 1,616
|
PHP include() basic question (I hope)
I hope someone can figure this out, because I can't seem to. I am working on a theme to the CMS phpwebsite. I have a theme.tpl file that uses {} variables to include database information for example {metatags} includes page spacific meta tags saved in the database. Now I have a file called theme.php where I can add custom php to add into the template. Something like:
$THEME["EXAMPLE"] = "This is a sample of including php code into your theme"; BUT, what I want to do is create some rather complex header and footer designs to put into the site. So what I want to do is add this to theme.php: $Theme["footer"] = include 'footer.tpl'; and {footer} to theme.tpl and have footer.tpl included in the final page. If you've been able to keep up so far, the problem is that the include() command defaults to the top of the page no matter where {footer} is put in theme.tpl. I could put the header and footer code all into theme.php, but everything would be easier to work with and edit if each part was in its own file. Hope someone can see a simple fix for this because I'm still pretty new to PHP and have no idea.
__________________
Laptop HP DM4t / i5-560M / 14.1 WXGA Widescreen / 1GB Radeon Mobility 6370 / 4GB RAM / 320 GB 7200rpm HD / DVD-RW / 802.11n & BT wireless First Build Abit IC7-G Max II Motherboard / 2.8C 800mhz P4 / 1024 DDR 3200 (2x 512 in Duel Channel) / Saphire Radeon 9800 Pro 128 / Samsung 120 GB SATA HD / Lite-On 16x DVD-ROM / NEC DVD-RW |
|
|
|
|
|
#2 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
Try:
PHP Code:
|
|
|
|
|
|
#3 |
|
Member (11 bit)
Premium Member
Join Date: Dec 2003
Location: Boston, MA
Posts: 1,616
|
Didn't work. Returned the errors:
Warning: file(footer.tpl): failed to open stream: No such file or directory in /var/www/html/phpwebsite/themes/Default/theme.php on line 11 Warning: implode(): Bad arguments. in /var/www/html/phpwebsite/themes/Default/theme.php on line 11 I know footer.tpl IS in the same dir as theme.php. It should be found. |
|
|
|
|
|
#4 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
Are you calling theme.php directly or including it in another file in another dir?
|
|
|
|
|
|
#5 |
|
Member (11 bit)
Premium Member
Join Date: Dec 2003
Location: Boston, MA
Posts: 1,616
|
Ok rats. I think I'm going to have to hard code the full address of the file. I was hoping I wouldn't have to do that to make the theme easy to edit for others. The file that calls theme.php is in root/mod/layout/class/layout.php and the file theme.php is in root/themes/ 'theme_name' /theme.php
|
|
|
|
|
|
#6 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
I think you have a variable for theme name, you can create the .tpl path in the script, this would be better than hard-coding.
|
|
|
|
|
|
#7 |
|
Member (11 bit)
Premium Member
Join Date: Dec 2003
Location: Boston, MA
Posts: 1,616
|
I did try:
$Theme["footer"] = implode("/n", file("{THEME_DIRECTORY}footer.tpl")); but it's still giving me: Warning: file({THEME_DIRECTORY}footer.tpl): failed to open stream: No such file or directory in /var/www/html/phpwebsite/themes/Default/theme.php on line 11 Warning: implode(): Bad arguments. in /var/www/html/phpwebsite/themes/Default/theme.php on line 11 I know that's the right variable for the theme dir because: {THEME_DIRECTORY}images/poweredby.jpg works to point to 'theme_name' /images/poweredby.jpg in an img src tag in the main theme.tpl file. What in the world am I missing here. Thanks for working this out with me by the way. |
|
|
|
|
|
#8 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
PHP doesn't expand template style {variable}s with their values, it only expands PHP $variables, so your code should besomething like:
PHP Code:
|
|
|
|
|
|
#9 |
|
Member (11 bit)
Premium Member
Join Date: Dec 2003
Location: Boston, MA
Posts: 1,616
|
almost there... Both
$theme_dir = "../phpwebsite/themes/Default"; $theme_dir = "var/www/html/phpwebsite/themes/Default"; remove all errors, but just don't show anything. Any other versions with forward slashes at the start or end show the same warnings. It's amazing how simple this 'should' be. |
|
|
|
|
|
#10 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
Would you please post your dir structure? I can't tell what's wrong without it.
|
|
|
|
|
|
#11 |
|
Member (11 bit)
Premium Member
Join Date: Dec 2003
Location: Boston, MA
Posts: 1,616
|
Main site http://www.anime-fiction.net/
Location of CMS files www.anime-fiction.net/phpwebsite True Path to CMS /var/www/html/phpwebsite All theme files are in phpwebsite/themes/ "theme_name" |
|
|
|
|
|
#12 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
Does hard-coding the path produce the required results? As adding a variable with path before the $Theme[] part doesn't really help.
Does phpwebsite keep a global variable with the theme's name? |
|
|
|
|
|
#13 |
|
Member (11 bit)
Premium Member
Join Date: Dec 2003
Location: Boston, MA
Posts: 1,616
|
OK,
$Theme["footer"] = implode("\n", file("http://www.anime-fiction.net/phpwebsite/themes/Default/footer.tpl")); does not give any errors, but it does not work either. If you enter the URL in a browser you will get the little tpl file, simply "testing foooter". I'm going to go snoop around the layout files. Maybe they coded a file type restriction somewhere... It isn't in the script documents. I found this in the layout.php file: class PHPWS_Layout extends PHPWS_Layout_Forms{ /** * Directory of current theme * * @var string * @access private */ var $theme_dir; /** * Directory of box files for current theme * * @var string * @access private */ var $box_dir; /** * Web address of current theme * * @var string * @access private */ var $theme_address; These are not universal variables. I tried both $theme_address and $theme_dir after taking out the page spacific $theme_dir line. Last edited by Staren; 10-18-2004 at 09:40 PM. |
|
|
|
|
|
#14 |
|
Member (11 bit)
Premium Member
Join Date: Dec 2003
Location: Boston, MA
Posts: 1,616
|
I had to like the one CMS that had next to no community support... SimpleCMS is too basic, and the Nukes & Mambo are just too huge, but at least they all have 10,000 people hanging around the forums that have done just about everything if you have a question.
|
|
|
|
|
|
#15 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
I'm sorry, I tried to help but looks like the problem is related to the CMS system and not PHP in general, and I'm not familiar with this CMS.
|
|
|
|
|
|
#16 |
|
Member (11 bit)
Premium Member
Join Date: Dec 2003
Location: Boston, MA
Posts: 1,616
|
Thanks anyway. I'll get this figured out at some point.
|
|
|
|
|
|
#17 |
|
Member (11 bit)
Premium Member
Join Date: Dec 2003
Location: Boston, MA
Posts: 1,616
|
Maybe you can figure this out... I did some hunting and managed to find someone who was useing this:
if ($insertme = readfile("http://stjohnsmorganhill.org/randomverse.mv" $THEME['RANDOMVERSE'] = $insertme; I adapted it to: if ($footer = readfile("footer.tpl" $THEME['footer'] = $footer; But I'm getting a Parse error on the first line. See anything that jumps out? |
|
|
|
|
|
#18 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
To fix the parse error:
PHP Code:
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|