PDA

View Full Version : Running PHP code in template


MomentumInc
06-04-2007, 07:53 PM
Hi. The navigation for our main site is generated dynamically. I'd like to use the same navigation at the top of our forum. Essentially, all I really need to do is include a php file in the "header" template.

I'm sure this question has been answered many times before, but I've been searching and searching and can't find anything that explains it completely (just something about defining variables somewhere that can be used in templates? or using hooks?)

Thanks.

Dismounted
06-05-2007, 07:36 AM
You will need to add a hook at global_start and use the ob_ functions. Searching on the vB.com forums would give you a few results. I'm also pretty sure it's in the manual somewhere as well.

Michael Morris
06-05-2007, 01:20 PM
You will need to add a hook at global_start and use the ob_ functions. Searching on the vB.com forums would give you a few results. I'm also pretty sure it's in the manual somewhere as well.
Partially wrong. global_start is already wrapped in an object buffer to allow backward compatibility with other PHP_INCLUDE scripts from vb 3.0.x days. All that is needed for a dynamic header is to replace the content of the header template with the var $phpinclude_output and then put the include file in the global start hook to set it up.

He can put an object buffer in an object buffer, though there's little need to do so.

MomentumInc
06-05-2007, 06:29 PM
Thanks. I figured out how to use hooks well enough to get Dismounted's suggestion working. I will look into the other suggestion as well if it's a 'better' way of doing it.