Page 2 of 2

Posted: Sat Dec 30, 2006 4:32 pm
by RobertGonzalez
I assume that since you are working with the phpBB template class code that you have the rest of the code base? Take a look through their functions.php code and find where they make they make the 'jumpbox' that is at the bottom of the forum pages. That is the perfect example of implementing templates within templates from their own code.

Posted: Sat Dec 30, 2006 5:02 pm
by richmix
Thanks for the tip, I'll check it out. Being new to OOP, I was a bit baffled when I tried to peruse the class Template. 8O Maybe Jumpbox will be a bit more manageable.

Posted: Sat Dec 30, 2006 6:14 pm
by richmix
Hmm. I looked through the function make_jumpbox($,$,$), but I'm not seeing it. I don't really know what I'm looking for, though; this code base is huge, and I'm not sure where it builds the actual output.

Posted: Sat Dec 30, 2006 7:56 pm
by RobertGonzalez
This is the part of the function that I was talking about...

Code: Select all

$template->set_filenames(array(
		'jumpbox' => 'jumpbox.tpl')
	);
	$template->assign_vars(array(
		'L_GO' => $lang['Go'],
		'L_JUMP_TO' => $lang['Jump_to'],
		'L_SELECT_FORUM' => $lang['Select_forum'],

		'S_JUMPBOX_SELECT' => $boxstring,
		'S_JUMPBOX_ACTION' => append_sid($action))
	);
	$template->assign_var_from_handle('JUMPBOX', 'jumpbox');
Now find the template file jumpbox.tpl and look at the template vars that are in it and how they come from the assign_vars method inside of this function.

Now go to the posting_body.tpl file. On about line 477 (subSilver) you will see the {JUMPBOX} template var. The jumpbox is made inside the function and the entire parsed template is passed as a template var handle to the main template being parsed (almost like an include, but the PHP parsing is done in the actual PHP script rather than the template).

Posted: Sat Dec 30, 2006 8:13 pm
by richmix
Hm.. I think I get it, but I'm a little confused about something. Won't this only work with template files? Or will it work with PHP files as well? The banner I want to include contains PHP, specifically PHP that shows or hides icons based on whether a logged in user is part of a member group.

Posted: Sun Dec 31, 2006 9:39 am
by RobertGonzalez
When using phpBB's template class you need to process all PHP inside the PHP script then push it to the templates by using the template objects method's. The way their code is written, you cannot execute PHP in the template.

Posted: Sun Dec 31, 2006 3:39 pm
by richmix
Yes, I know. I'm using a mod that allows PHP to be used in the templates, but that's another matter entirely. My question was about the following line:

Code: Select all

$template->set_filenames(array(
                'jumpbox' => 'jumpbox.tpl')
        );
My nav bar isn't a .tpl file, as the rest of my site does not use phpBB's template system. I imagine, then, that the approach to making this work would be entirely different when using a .php file instead of a .tpl file (because I would venture to guess that phpBB's template system isn't designed to use php files as output methods). Unfortunately, I can't try it myself because again, I don't know how, and since I don't have a testing environment available that supports mySQL (my university's firewall is depressingly efficient), I can't even play around with it for weeks until I get it right. I realize I'm a bit in over my head here and that if I want to learn it I should start with more basic OOP, but I just need this one thing to work. Am I pretty much out of luck until I learn phpBB's template system in more detail?

Posted: Sun Dec 31, 2006 4:09 pm
by RobertGonzalez
If the files are not too big, maybe you can post your nav code and the template that you want to push it into. Maybe we can work out a way to do what you want.

Posted: Sun Dec 31, 2006 6:30 pm
by richmix
Ok, I jerry-rigged it.

I didn't think this would work, but with the advice from you and some other people, I worked out a method for it.

In page_header.php, I set a flag so I could use an if statement in my nav bar to tell it not to re-include forum files if it was already a forum page:

page_header.php, line 489:

Code: Select all

define('FORUM_SKIP_VALIDATION', TRUE);
Then on line 491, I declared a 'NAV_BAR' variable in the template variables array:

Code: Select all

$template->assign_vars(array(
	'NAV_BAR' => include_once($_SERVER['DOCUMENT_ROOT'] . "/inc/logoNav.php"))
	);
So in my overall_header.tpl, I just added {NAV_BAR} to the very beginning of the file. The code was working fine, with one small exception; lo and behold, it was printing a single number 1 after my header on a new line, for apparently no reason at all. I fixed it by modifying the variable declaration to:

Code: Select all

$template->assign_vars(array(
	'NAV_BAR' => trim(include_once($_SERVER['DOCUMENT_ROOT'] . "/inc/logoNav.php"), "1") . "\n")
	);
The 1 is gone, and the HTML source looks nice and neat. Now here's hoping I didn't mess with any forum functions or variables inadvertently. :D Thanks for the help! It's hugely appreciated!

Posted: Sun Dec 31, 2006 8:42 pm
by RobertGonzalez
You know, theoretically that should not work. Keep an eye on it to make sure it stays working. And I'm glad you got it working. Happy New Year.

Posted: Sun Dec 31, 2006 10:05 pm
by richmix
Everah wrote:You know, theoretically that should not work. Keep an eye on it to make sure it stays working. And I'm glad you got it working. Happy New Year.
That's what I thought too, which is why I gave up on it after the first time I tried it with errors. But the errors are gone and it's doing what I want it to do, so I'm happy. Heh.