vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Passing variables into custom templates (https://vborg.vbsupport.ru/showthread.php?t=228685)

stevegrant 11-23-2009 03:52 PM

Passing variables into custom templates
 
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
Code:

$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:
Code:

...

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

<div class="sweb_pl_block">
  <h1></h1>
</div>

Any ideas?

Lynne 11-23-2009 04:36 PM

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 11-24-2009 04:14 AM

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 11-24-2009 10:05 PM

1 Attachment(s)
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 12-01-2009 05:48 AM

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


All times are GMT. The time now is 03:52 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00976 seconds
  • Memory Usage 1,716KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete