PDA

View Full Version : How to eval template vB4


James Birkett
12-13-2009, 07:34 PM
eval('$HTML = "' . fetch_template('shoutbox_archive') . '";');

This is my current method of fetching a template, how do we fetch a template in vBulletin 4?

Could somebody turn that code into vb4-acceptable syntax?

EDIT: So far I have:
$templater = vB_Template::create('shoutbox_archive');

What variables am I meant to register? Every variable that's used inside the template?

Lynne
12-13-2009, 07:55 PM
You register any variable you plan to use in the template - usually not also stylevars, or vboptions or session - the common ones. But, if you use them, and don't register them and they don't work, then add them in.

James Birkett
12-14-2009, 02:22 PM
I register all variables except stylevars, vboptions and sessions? Does sessions include the session URL? Do I need to register the session URL?

Also, what about $vbcollapse?

The template is already created (with variables) I just need to call the template for a custom URL and register all variables, however i'm not sure which ones don't need to be registered.

Thanks in advance.

EDIT:
Old code:
eval('$HTML = "' . fetch_template('shoutbox_archive') . '";');

New code:
$templater = vB_Template::create('shoutbox_archive');
$templater->register('cansearch', $cansearch);
$templater->register('shouthtml', $shouthtml);
$templater->register('vbcollapse', $vbcollapse);
$templater->register('TS', $TS);
$templater->register('T4', $T4);
$templater->register('TY', $TY);
$templater->register('search', $search);
$templater->register('top_shouter_num', $top_shouter_num);
$templater->register('TopTen', $TopTen);
$templater->register('pagenav', $pagenav);
$HTML = $templater->render();

Is that new code right? I.e. does it mimic the old code? (assuming all of my variables are registered correctly)

Lynne
12-14-2009, 03:35 PM
It doesn't hurt to register a variable that isn't needed (like a stylevar or session). So, if you aren't sure if you need to register them or not, just put them in anyway.

James Birkett
12-14-2009, 03:39 PM
Hey Lynne,

Does the above code mimic the old code, just in the new syntax?

Old:
eval('$HTML = "' . fetch_template('shoutbox_archive') . '";');

Lynne
12-14-2009, 03:44 PM
Yeah, it looks fine to me. But then, I've always been one who just jumps in and tries it out - thank God for test sites!

James Birkett
12-14-2009, 03:52 PM
I'm trying to output this to a ?do=archive and it won't show anything currently, thanks for your help though, i'm sure i'll figure something out!

Lynne
12-14-2009, 03:56 PM
I'm trying to output this to a ?do=archive and it won't show anything currently, thanks for your help though, i'm sure i'll figure something out!
And is $HTML registered to be used in whatever template used in do=archive? (I have no idea where that page is).

James Birkett
12-15-2009, 11:17 AM
do=archive is an archive for my shoutbox.

So if I assign the template to variable $HTML, that variable has to be registered also?

I'll fix that little error.

Lynne
12-15-2009, 03:20 PM
do=archive is an archive for my shoutbox.

So if I assign the template to variable $HTML, that variable has to be registered also?

I'll fix that little error.
Yep, all variables must be registered for use in a template now.

James Birkett
12-15-2009, 03:44 PM
I managed to get parts of my template working, thanks very much Lynne!

Trial and error from here now.

Lynne
12-15-2009, 03:56 PM
Trial and error from here now.
You are my kind of coder. :)