Within a .tpl file, setting $var equal to {var}
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
This is the part of the function that I was talking about...
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).
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 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).
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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:
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?
Code: Select all
$template->set_filenames(array(
'jumpbox' => 'jumpbox.tpl')
);- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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:
Then on line 491, I declared a 'NAV_BAR' variable in the template variables array:
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:
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.
Thanks for the help! It's hugely appreciated!
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);Code: Select all
$template->assign_vars(array(
'NAV_BAR' => include_once($_SERVER['DOCUMENT_ROOT'] . "/inc/logoNav.php"))
);Code: Select all
$template->assign_vars(array(
'NAV_BAR' => trim(include_once($_SERVER['DOCUMENT_ROOT'] . "/inc/logoNav.php"), "1") . "\n")
);- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.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.