vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Loading Template Contents into Plugin (https://vborg.vbsupport.ru/showthread.php?t=230512)

consolegaming 12-18-2009 11:00 PM

Loading Template Contents into Plugin
 
I am in the process of trying to upgrade a plugin of mine for vb4 and I'm trying to reproduce the effect of the following code:

PHP Code:

eval('$activeonlineusers[\'team\'] .= ", ' fetch_template('forumhome_loggedinuser') . '";'); 


I have tried two different things:
PHP Code:

$activeonlineusers['team'] .= ", "$vbulletin->templatecache["forumhome_loggedinuser"]; 


and:
PHP Code:

$activeonlineusers['team'] .= ", ".$templater->render();
$templater vB_Template::create('forumhome_loggedinuser'); 


The latter just shows the commas and the former shows something resembling the below:
Code:

# Hello $final_rendered = ' ' . vB_Template_Runtime::fetchStylevar("dirmark") . ' ' . $loggedin['musername'] . '' . $loggedin['invisiblemark'] . '' . $loggedin['buddymark'] . '
# ';Hello $final_rendered = ' ' . vB_Template_Runtime::fetchStylevar("dirmark") . ' ' . $loggedin['musername'] . '' . $loggedin['invisiblemark'] . '' . $loggedin['buddymark'] . '
';

Hello = what I put in, instead of the comma's to make sure the seperator was being added.

I'm probably just missing something really obvious but sometimes you get to the point where you just can't see the answer lol. It's not an issue with registering variables because it does output (another plugin uses this array to replace the one that is outputted).

Lynne 12-19-2009 01:32 AM

Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide

consolegaming 12-19-2009 12:57 PM

I've read that thread a few times (before posting this) but I'm not sure it actually helps my situation.

I've just tried registering the variable as a seperate variable (which isn't what I want to do - I want to replace the one that's already getting displayed - hence no template edits) and that still didn't work.

It seems that the output of:

PHP Code:

$templater vB_Template::create('forumhome_loggedinuser');

$activeonlineusers['team'] .= "Hello".$templater->render(); 

is only showing the Hello's. the output of the $templater->render() appears to be blank. And this plugin is assigned to the forumhome_loggedinuser hook. I don't see why this template would appear blank.

As I said I do register the variables (in another plugin i.e. once the variable has finished being set). Though in the final thing I just want to replace the existing $activeusers variable without having to make a template change.

Lynne 12-19-2009 03:19 PM

Well, if you look at the template forumhome_loggedinuser, it needs the variable $loggedin. You have done nothing to register that variable for use in the template.

PHP Code:

            $templater vB_Template::create('forumhome_loggedinuser');
                
$templater->register('loggedin'$loggedin);
            
$activeonlineusers['team'] .= "Hello".$templater->render(); 


consolegaming 12-19-2009 03:27 PM

Ah, I think that's the breakthrough I needed. It seems to have worked from the quick test I did.

I had made the assumption I didn't need to register any existing variables because I thought they would already be registered (otherwise they wouldn't work in the first place). Now I know that I'll need to re-register them in that sort of situation.


All times are GMT. The time now is 06:33 AM.

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.03232 seconds
  • Memory Usage 1,733KB
  • 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
  • (1)bbcode_code_printable
  • (5)bbcode_php_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