PDA

View Full Version : Loading Template Contents into Plugin


consolegaming
12-18-2009, 11:00 PM
I am in the process of trying to upgrade a plugin of mine for vb4 and I'm trying to reproduce the effect of the following code:

eval('$activeonlineusers[\'team\'] .= ", ' . fetch_template('forumhome_loggedinuser') . '";');


I have tried two different things:
$activeonlineusers['team'] .= ", ". $vbulletin->templatecache["forumhome_loggedinuser"];


and:
$activeonlineusers['team'] .= ", ".$templater->render();
$templater = vB_Template::create('forumhome_loggedinuser');


The latter just shows the commas and the former shows something resembling the below:
# Hello $final_rendered = ' ' . vB_Template_Runtime::fetchStylevar("dirmark") . ' ' . $loggedin['musername'] . '' . $loggedin['invisiblemark'] . '' . $loggedin['buddymark'] . '
# ';Hello $final_rendered = ' ' . vB_Template_Runtime::fetchStylevar("dirmark") . ' ' . $loggedin['musername'] . '' . $loggedin['invisiblemark'] . '' . $loggedin['buddymark'] . '
';

Hello = what I put in, instead of the comma's to make sure the seperator was being added.

I'm probably just missing something really obvious but sometimes you get to the point where you just can't see the answer lol. It's not an issue with registering variables because it does output (another plugin uses this array to replace the one that is outputted).

Lynne
12-19-2009, 01:32 AM
Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide (https://vborg.vbsupport.ru/showthread.php?t=228078)

consolegaming
12-19-2009, 12:57 PM
I've read that thread a few times (before posting this) but I'm not sure it actually helps my situation.

I've just tried registering the variable as a seperate variable (which isn't what I want to do - I want to replace the one that's already getting displayed - hence no template edits) and that still didn't work.

It seems that the output of:

$templater = vB_Template::create('forumhome_loggedinuser');

$activeonlineusers['team'] .= "Hello".$templater->render();

is only showing the Hello's. the output of the $templater->render() appears to be blank. And this plugin is assigned to the forumhome_loggedinuser hook. I don't see why this template would appear blank.

As I said I do register the variables (in another plugin i.e. once the variable has finished being set). Though in the final thing I just want to replace the existing $activeusers variable without having to make a template change.

Lynne
12-19-2009, 03:19 PM
Well, if you look at the template forumhome_loggedinuser, it needs the variable $loggedin. You have done nothing to register that variable for use in the template.

$templater = vB_Template::create('forumhome_loggedinuser');
$templater->register('loggedin', $loggedin);
$activeonlineusers['team'] .= "Hello".$templater->render();

consolegaming
12-19-2009, 03:27 PM
Ah, I think that's the breakthrough I needed. It seems to have worked from the quick test I did.

I had made the assumption I didn't need to register any existing variables because I thought they would already be registered (otherwise they wouldn't work in the first place). Now I know that I'll need to re-register them in that sort of situation.