Include header and footer outside of phpbb

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Ideas Centre
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Locked
kingdruid
Registered User
Posts: 17
Joined: Tue Oct 09, 2007 12:33 am

Include header and footer outside of phpbb

Post by kingdruid » Tue Jul 29, 2008 5:49 am

I searched and couldn't find the answer:

I have a header and footer that I customized for phpbb and it works fine.

I have my index and other pages outside of the phpbb forum and directory and want to include the php header and footer. I know I can do it if if I specify a body template, but I want to use a locel php file outside of the phpbb template directory and don't want to enable PHPINCLUDE in the forum.

If I try to leave out the $body template I get an error:
template->_tpl_load(): No file specified for handle body


is there anyway I can tell it to include the header and footer for a page and just use plain text for the body with echo statements?

I also want to use the header and footer so it shows the user if he is logged and receives pm's.

User avatar
karlsemple
Former Team Member
Posts: 39802
Joined: Mon Nov 01, 2004 8:54 am
Location: Hereford, UK
Contact:

Re: Include header and footer outside of phpbb

Post by karlsemple » Tue Jul 29, 2008 5:53 am

Knowledge Base - Add a New Custom Page to phpBB You need to use the phpBB session management so you can then use the template engine which would allow you to include the header and footer files. The php file only need to include the html file, you can then use the HTML file you show your info by creating it as a normal HTML page with the added bonus you can then use the include template tags for the footer and header :)
Image

kingdruid
Registered User
Posts: 17
Joined: Tue Oct 09, 2007 12:33 am

Re: Include header and footer outside of phpbb

Post by kingdruid » Tue Jul 29, 2008 7:02 pm

Yeah I got all that and understand it, but what I want to do is exclude:
$template->set_filenames(array(
'body' => 'aboutus_body.html',
));

and include only the header and footer and add my own text. The reason is I don't want to enable PHP in the template files, but I need to run php code on the pages. I would just like to add the header and footer and everything in the body will be run from the php file.

kingdruid
Registered User
Posts: 17
Joined: Tue Oct 09, 2007 12:33 am

Re: Include header and footer outside of phpbb

Post by kingdruid » Tue Jul 29, 2008 7:11 pm

I guess I can turn on PHP and include a php file in the template, but I tried that once and for some reason if I update the php file it continues to include an old copy of the php file????? So I figured I am just going to include the header and footers somehow and have my php code in the main php file.

Let me know if anyone has any ideas?

kingdruid
Registered User
Posts: 17
Joined: Tue Oct 09, 2007 12:33 am

Re: Include header and footer outside of phpbb

Post by kingdruid » Tue Jul 29, 2008 7:26 pm

Also another thing is that when I did include a php file in the template file it didn't carry over the styles so I couldn't use them in the php file.

kingdruid
Registered User
Posts: 17
Joined: Tue Oct 09, 2007 12:33 am

Re: Include header and footer outside of phpbb

Post by kingdruid » Wed Jul 30, 2008 4:35 am

Or would you guys have any idea as to why when I include a php file in the template, then I go back and edit that php file it still shows the old version? I searched my ftp for multiple copies of the php file, but didn't find anything. Would you have any idea why it would cache the old page? I went into the admin control panel and cleared the cache for the style.

User avatar
karlsemple
Former Team Member
Posts: 39802
Joined: Mon Nov 01, 2004 8:54 am
Location: Hereford, UK
Contact:

Re: Include header and footer outside of phpbb

Post by karlsemple » Wed Jul 30, 2008 7:13 am

If you have followed that guide you will already have a php file which calls the template html file? Run your php in that php file and then assign the result to a template variable and then pass that to your HTML file.
Image

kingdruid
Registered User
Posts: 17
Joined: Tue Oct 09, 2007 12:33 am

Re: Include header and footer outside of phpbb

Post by kingdruid » Wed Jul 30, 2008 5:35 pm

karlsemple wrote:If you have followed that guide you will already have a php file which calls the template html file? Run your php in that php file and then assign the result to a template variable and then pass that to your HTML file.

Cool thanks I'll try that. I shouldn't have a problem with that I just have to rewrite my code.

kingdruid
Registered User
Posts: 17
Joined: Tue Oct 09, 2007 12:33 am

Re: Include header and footer outside of phpbb

Post by kingdruid » Wed Jul 30, 2008 7:23 pm

karlsemple wrote:If you have followed that guide you will already have a php file which calls the template html file? Run your php in that php file and then assign the result to a template variable and then pass that to your HTML file.
Your a Genius!!!

That works perfectly and I also added this if anybody else wants runs into this problem:

ob_start(); // start buffer
include ("news.php");
$content = ob_get_contents(); // assign buffer contents to variable
ob_end_clean(); // end buffer and remove buffer contents

$template->assign_vars(array(
'M_NEWS' => $content)
);

vrjourney
Registered User
Posts: 20
Joined: Sat Apr 10, 2004 11:10 pm

Re: Include header and footer outside of phpbb

Post by vrjourney » Tue Feb 16, 2010 11:49 pm

We're in a position where adding new pages in as templates isn't going to happen - hired gun developer who's got enough on his plate without learning the finer points of phpBB's templating system - so found this to be of interest.

We appear to have solved it by modifying the "official" approach from the KB, and using the display() function on $template. There's a "core" column in our architecture diagram, which is the only thing interfacing with phpBB - all other sections of the site will talk to phpBB through that. For the header and footer this means:

/testApp/index.php:

Code: Select all

<?php include("../core/core.php");
write_page_header("My page"); ?>

<!-- Page content goes here -->

<?php write_page_footer(); ?>
/core/core.php:

Code: Select all

<?php
/*
 * BEGIN PHPBB STANDARD PAGE SETUP
 */
define('IN_PHPBB', true);
$phpbb_root_path = '../forum/';
$website_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
/*
 * END PHPBB STANDARD PAGE SETUP
 */

/*
 * Outputs the HTML for the top of the page
 */
function write_page_header($page_title){
	global $template;
	page_header($page_title);
	$template->set_filenames(array(
	'body' => 'overall_header.html',
	));
	$template->display('body');
}

/*
 * Outputs the HTML for the bottom of the page and does board-related tidying up
 */
function write_page_footer(){
	global $template;
	$template->set_filenames(array(
	'body' => 'overall_footer.html',
	));
	$template->display('body');
	page_footer();
}
?>
Some niceties (like a label and URL for the "who's online" list) remain, but this seems to give us a header and footer along with all the user session stuff.

If there's a problem with this approach, I'd really like to know about it!

n3wb13
Registered User
Posts: 25
Joined: Sat Dec 25, 2010 12:23 am

Re: Include header and footer outside of phpbb

Post by n3wb13 » Fri Dec 31, 2010 4:00 am

hi, ive tried this, i have an error on line 9

any ideas please? (am learning and i dont know whats wrong)

thanks

Locked

Return to “[3.0.x] Support Forum”