Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 10-16-2004, 11:34 PM   #1
Member (11 bit)
Premium Member
 
Staren's Avatar
 
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
Staren is offline   Reply With Quote
Old 10-17-2004, 12:36 AM   #2
aym
Registered User
 
aym's Avatar
 
Join Date: Nov 2001
Posts: 1,965
Try:
PHP Code:
$Theme["footer"] = implode("\n"file("footer.tpl")); 
aym is offline   Reply With Quote
Old 10-17-2004, 10:28 AM   #3
Member (11 bit)
Premium Member
 
Staren's Avatar
 
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.
Staren is offline   Reply With Quote
Old 10-17-2004, 04:57 PM   #4
aym
Registered User
 
aym's Avatar
 
Join Date: Nov 2001
Posts: 1,965
Are you calling theme.php directly or including it in another file in another dir?
aym is offline   Reply With Quote
Old 10-17-2004, 05:26 PM   #5
Member (11 bit)
Premium Member
 
Staren's Avatar
 
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
Staren is offline   Reply With Quote
Old 10-17-2004, 05:31 PM   #6
aym
Registered User
 
aym's Avatar
 
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.
aym is offline   Reply With Quote
Old 10-17-2004, 06:06 PM   #7
Member (11 bit)
Premium Member
 
Staren's Avatar
 
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.
Staren is offline   Reply With Quote
Old 10-17-2004, 07:31 PM   #8
aym
Registered User
 
aym's Avatar
 
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:
$theme_dir "path/to/theme";
// ...
$Theme["footer"] = implode("\n"file("$theme_dir/footer.tpl")); 
aym is offline   Reply With Quote
Old 10-17-2004, 08:10 PM   #9
Member (11 bit)
Premium Member
 
Staren's Avatar
 
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.
Staren is offline   Reply With Quote
Old 10-18-2004, 05:46 AM   #10
aym
Registered User
 
aym's Avatar
 
Join Date: Nov 2001
Posts: 1,965
Would you please post your dir structure? I can't tell what's wrong without it.
aym is offline   Reply With Quote
Old 10-18-2004, 08:00 AM   #11
Member (11 bit)
Premium Member
 
Staren's Avatar
 
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"
Staren is offline   Reply With Quote
Old 10-18-2004, 08:09 AM   #12
aym
Registered User
 
aym's Avatar
 
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?
aym is offline   Reply With Quote
Old 10-18-2004, 09:22 PM   #13
Member (11 bit)
Premium Member
 
Staren's Avatar
 
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.
Staren is offline   Reply With Quote
Old 10-18-2004, 09:44 PM   #14
Member (11 bit)
Premium Member
 
Staren's Avatar
 
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.
Staren is offline   Reply With Quote
Old 10-19-2004, 08:09 AM   #15
aym
Registered User
 
aym's Avatar
 
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.
aym is offline   Reply With Quote
Old 10-19-2004, 01:41 PM   #16
Member (11 bit)
Premium Member
 
Staren's Avatar
 
Join Date: Dec 2003
Location: Boston, MA
Posts: 1,616
Thanks anyway. I'll get this figured out at some point.
Staren is offline   Reply With Quote
Old 10-19-2004, 10:05 PM   #17
Member (11 bit)
Premium Member
 
Staren's Avatar
 
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?
Staren is offline   Reply With Quote
Old 10-20-2004, 07:20 AM   #18
aym
Registered User
 
aym's Avatar
 
Join Date: Nov 2001
Posts: 1,965
To fix the parse error:

PHP Code:
if ($footer readfile("footer.tpl"))
    
$THEME['footer'] = $footer
However, unlike file(), readfile() outputs the file contents too, so this may not be what you're looking for.
aym is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:55 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2