PDA

View Full Version : Loading Template Contents into Plugin


consolegaming
19 Dec 2009, 01:00
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
19 Dec 2009, 03:32
Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide (http://www.vbulletin.org/forum/showthread.php?t=228078)

consolegaming
19 Dec 2009, 14:57
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
19 Dec 2009, 17:19
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
19 Dec 2009, 17:27
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.