PDA

View Full Version : Passing variables into custom templates


stevegrant
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:

predictionleague.php
$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_page_templates();
$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>
</div>
{vb:raw footer}
</body>
</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!

Output:
<div class="sweb_pl_block">
<h1></h1>
</div>
Any ideas?

Lynne
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.

stevegrant
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...

winstone
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

stevegrant
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