Thread: Code help
View Single Post
  #10  
Old 01-10-2010, 05:41 AM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In the code given above, I see lots of variables used in the template that are not registered, like $pbstyle, $pbthreadid, $pbthreadtitle etc. Basically none of the variables you use in the template are registered. Please read the tutorial Lynne linked you to again, especially the part about "Save into a variable for later use in custom template".

For $threadid for example, you need to register the variable for your bigblock template and for your smallblock template:
PHP Code:
$templater->register('pb_latestthreads_bigblock'$pblatest_bigblocks);
   
$templater->register('threadid'$threadid);
$pblatest_bigblocks .= $templater->render(); 
What I changed: Added the $templater->register line to register $threadid. Added the dot in the last line before the =, since this is in a while-loop and you don't want the result to be overwritten every time, but added. Note how you had that point in your old eval, too.
Now you can call $threadid in your template pb_latestthreads_bigblock by inserting {vb:raw threadid}.

To be able to call the variable you saved the template into ($pblatest_bigblock) in your pb_latestthreads_area template, you again need to register it:

Your code there:
PHP Code:
$templater vB_Template::create('mytemplate');
    
$templater->register('pb_latestthreads_area'$PBLatestThreads);    
    
$PBLatestThreads $templater->render(); 
This cannot work. Note how you did not insert the template name (it still reads mytemplate!) in first line. Then, in second line, you don't register an existing variable you want to use in the template, but try to register the variable you want to save the template into. This makes no sense: You don't want to call that template inside that very template. Here you would register the variable you saved the bigblocks template into, to be able to call it in the latestthreads area template. Furthermore, you need to decide where you want to call this last template, the area template. If you want to show the contents of your latestthreads_area template on forumhome, for example, you'd need to preregister it for that.

IT would look something like that:
PHP Code:
$templater vB_Template::create('pb_latestthreads_area'); // create the template
    
$templater->register('pblatest_bigblocks'$pblatest_bigblocks); // register $pblatest_bigblocks to be able to use {vb:raw pblatest_bigblocks} in template pb_latestthreads_area
    
$templatevalues['PBLatestThreads'] = $templater->render(); // rendering template into a variable suitable for preregistering for use in existing template 
    
vB_Template::preRegister('FORUMHOME'$templatevalues); // preregister variable from line above to be able to use {vb:raw PBLatestThreads} on forumhome 
I would like to advice you to first go with some simple hello world examples to learn the logic of registering templates. Your construction is quite complicated to start with. If you want to look at a code example, download my social groups on forum home mod - it uses basically the same construction.

Basically:
- bigblock template: register every variable you want to use inside this template, save into variable
- smallblock template: register every variable you want to use inside this template, save into variable
- area template: register every variable you want to use inside this template, including the variables you saved bigblock and smallblock templates into; save area template into variable, then preregister this variable for use in existing template
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03524 seconds
  • Memory Usage 1,792KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete