View Full Version : Passing variables into custom templates

23 Nov 2009, 17:52
I'm creating a custom page (or rather a custom set of pages) that are referenced off the main navbar (thanks to the tutorial in the articles section on here :) ), but I don't seem to be able to get variables from $templater->register() to actually display within my template :(

Code extracts:

$navbits = array('prediction-league' => 'Prediction League');
$variable_to_pass = 'Passing through...';

$navbar = render_navbar_template(construct_navbits($navbits));
$templater = vB_Template::create('sweb_prediction_league');
$templater->register('navbar', $navbar);
$templater->register('variable_to_pass', $variable_to_pass);
print_output($templater->render());Template sweb_prediction_league:

<body style="text-align:left">

{vb:raw header}
{vb:raw navbar}
{vb:raw toolbar}

<div class="sweb_pl_block">
<h1>{vb:raw variable_to_pass}</h1>
{vb:raw footer}
</html>The bizarre thing is that the navbar modification (i.e. adding the breadcrumb trail) DOES get passed through and displayed correctly, but variable_to_pass doesn't!

<div class="sweb_pl_block">
Any ideas?

23 Nov 2009, 18:36
Is there anything in your error_logs? (If you don't know where they are, ask your host.)

You don't have toolbar registered either, is that showing up? Your code looks like it should be fine.

24 Nov 2009, 06:14
Nothing in the error logs, and as it's currently running on localhost anyway, I'm outputting all errors and warnings to the screen.

Good spot on the toolbar, the joys of copy and paste - I don't actually need that one! :)

There's something very odd going on, I've also just had a fiddle around to see if I could still print_r the $vbulletin object before I run vb_Template::create but it now does nothing, and even commenting out the template commands at the end of the script has no effect - the template is still displayed!! Don't think it's a caching issue as I've cleared the cache a number of times...

25 Nov 2009, 00:05
try these files and see if it is working, its the first custom page I created following the tutorials here

upload the test.php into root of your forum, import the template.xml file (contains 3 custom templates named test, test_bit, loop_bit), then just open test.php file in browser

see if it is working

01 Dec 2009, 07:48
Thanks for your help - got it working in the end, although I haven't actually changed anything... slightly strange, but never mind! :D