PDA

View Full Version : "new" vbTemplate help


jasharen
09-02-2012, 10:07 PM
Its been a long time for me and I'm trying to get my forum back up and going.

I have upgraded to vb4.2 and am trying to get an old mod working again. Its pretty simple just one issue.

It uses fetch_template which I understand is deprecated. The new format is:

$templater = vB_Template::create('forumhome_event');
$templater->register('callink', $callink);
$templater->register('daysevents', $daysevents);
$templater->register('eventdate', $eventdate);
$templater->register('eventdates', $eventdates);
$upcomingevents = $templater->render();

My mod searchs for a BB element in a post and replaces it with the template using the hook postbit_display_complete:

eval('$newvaluetodisplay= "' . fetch_template("postbit_mytemplate") . '";');

It then does a search and replace on

$newpostmessage = preg_replace("@\[myelement$i\]@i", "$newvaluetodisplay", $post['message']);

I've temporarily fixed it by just by moving the contents of the template into the code itself but I'd like it to be cleaner. :)

Any suggestions?

kh99
09-02-2012, 10:18 PM
Sorry, I'm not sure what you're asking - you seem to have it figured out. Just replace your eval line with:

$templater = vB_Template::create('postbit_mytemplate');
$newpostmessage = $templater->render();


and you only need one or more register() calls if your postbit_mytemplate uses variables.

Oh, and you'd also need to convert your template to vb4 format, if it uses any <if> tags or includes any variables.

jasharen
09-02-2012, 10:21 PM
wow I feel stupid now, only thing I was missing is

$newpostmessage = $templater->render();

It just wasn't sinking in no matter how many times I stared at it :)

Thanks, though I feel foolish now! lol