PDA

View Full Version : How to eval template vB4


James Birkett
13 Dec 2009, 20:34
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
13 Dec 2009, 20:55
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
14 Dec 2009, 15:22
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
14 Dec 2009, 16:35
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
14 Dec 2009, 16:39
Hey Lynne,

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

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

Lynne
14 Dec 2009, 16:44
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
14 Dec 2009, 16:52
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
14 Dec 2009, 16:56
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
15 Dec 2009, 12:17
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
15 Dec 2009, 16:20
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
15 Dec 2009, 16:44
I managed to get parts of my template working, thanks very much Lynne!

Trial and error from here now.

Lynne
15 Dec 2009, 16:56
Trial and error from here now.
You are my kind of coder. :)