UseBB Community

The official board for UseBB help and discussion

UseBB Community » Help & Support » How do I: Put a PHP include in a Tempate File?

How do I: Put a PHP include in a Tempate File?

Moderators: Gaia.

Page: 1

Author Post
Member
Registered: Apr 2007
Posts: 13
I'm working UseBB into a site of mine and I use PHP includes for the main site header and menu on all the regular pages in my site. I'd like to use those same includes in the Template for UseBB. How exactly do I do that?
I attempted:

<?php include('../includes/header.php'); ?>


and

{php} include('../includes/header.php'); {/php}


But neither shows the header. I'm sorry if this is a stupid request, but I'm rather PHP challenged. Any help anyone here can offer would be greatly appreciated.
Thank you,

Dawn
Member
Registered: May 2005
Posts: 294
Location: 98671
You talking adding something similar to what you see on this forum, at the very top above UseBB logo.

Or integrating into your site.
« Last edit by William on Wed Apr 11, 2007 4:39 am. »
Developer
Registered: Apr 2004
Posts: 2202
Location: Belgium
UseBB des not support including files in the templates.

You could try including them in global.tpl.php and capture the output using an output buffer (using ob_start() etc) and place the result in the right template by splitting the template's string.
_______________
--Dietrich (developer)
UseBB roadmap, dev mailing list & weblog
Member
Registered: Apr 2007
Posts: 13
First of all, thank you for the quick response!

Yes, it's something I want to integrate into the template of UseBB.

Dietrich, it sounds like you're on the right track there. So I would include the files as normal in the global.tpl.php? Then I would capture the output using an output buffer that would split the string? I'm assuming you mean, I would add something like this:

.... interrupt template code';

capture the output here?

echo'resume template code....

Exactly how would I use the using "ob_start()" to do that. I'm sorry, I really am PHP challenged. I am really grateful for your assistance.

Dawn
Developer
Registered: Apr 2004
Posts: 2202
Location: Belgium
Use ob_start(), then include the file, put the contents in a string using ob_get_contents() and stop the buffer using ob_end_clean(). You may then insert the string variable into the template.

Don't use echo() or print(), it has no effect.
_______________
--Dietrich (developer)
UseBB roadmap, dev mailing list & weblog
Member
Registered: Apr 2007
Posts: 13
Does one of the template files have an example I could look at to see exactly how that works?

Dawn
Developer
Registered: Apr 2004
Posts: 2202
Location: Belgium
UseBB does not contain any of these hacks, but you could do like the following:

<?php

// ...

ob_start();
include(ROOT_PATH.'../something.php');
$include = ob_get_contents();
ob_end_clean();

// ...

$template['something'] = '
foo {bar}
'.$include.'
foo {bar}';

?>


I hope you understand what I mean, the templates are just string array values which you could split and insert a variable ($include) in it.
_______________
--Dietrich (developer)
UseBB roadmap, dev mailing list & weblog
Member
Registered: Apr 2007
Posts: 13
I think I'm getting it. I swear, I wish I understood scripting languages better.
I'll give it a shot and see what happens.
I really do appreciate your help, Dietrich. I love UseBB ... it rocks!

Dawn
Member
Registered: Apr 2007
Posts: 13
EUREKA! Thank you so much Dietrich!
Through a little trial and error, my PHP-challenged self finally got it to work.
Your assistance is much appreciated!

Dawn
Member
Registered: May 2007
Posts: 7
Location: Nigeria
Dawnrae,

my trial & error not working yet.

pls let me learn know how you are able to fix this. (templates & pages edited)

Olufemi
_______________
Member
Registered: Apr 2007
Posts: 13
I'm at work right now, but I'll send you some code examples when I get home this evening.

Dawn
Member
Registered: Apr 2007
Posts: 13
Okay, here's how I got it to work. In global.tpl.php, below the statement

if ( !defined('INCLUDED') )
exit();


I placed the following:

ob_start();
include(ROOT_PATH.'../includes/header.php');
$my_header = ob_get_contents();
ob_end_clean();


Then, within the template, in the area I wanted the header to appear, I did this:

 
<!-- HEADER BEGINS -->
'.$my_header.'
<!-- HEADER ENDS -->


Hope that helps!

Dawn
Member
Registered: May 2007
Posts: 7
Location: Nigeria
It works perfectly well.

Thanks very much. I appreciate your help.

olufemi
_______________
Member
Registered: Apr 2007
Posts: 13
No problem. Glad to be of help.

Dawn

Page: 1

UseBB Community » Help & Support » How do I: Put a PHP include in a Tempate File?

UseBB Community is powered by UseBB 1 Forum Software