vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   A little confused now (calling a template) (https://vborg.vbsupport.ru/showthread.php?t=227892)

Lynne 11-16-2009 03:32 AM

Quote:

Originally Posted by Omegatron (Post 1914907)
yeah you did I tried the str_replace and it did not work I asked if you knew why it did not.

I can't follow this on two sites. I guess I'll check the other thread tomorrow morning. However, if you didn't post all your code over there, then I'm not gonna be able to help. (Actually, you should probably continue this over here if you need code help since they don't like discussing plugin code and such over there.) So, post your code here and we'll see if we can figure out what is wrong. Include template code if you are calling templates also.

Pitman 11-16-2009 05:58 AM

Quote:

Originally Posted by Lynne (Post 1913914)
First, you need to register the variables you will be using in the template and then you need to render it.
Example from one of mine using a template_hook:
PHP Code:

    $templater vB_Template::create('my_custom_template'); 
        
$templater->register('a_variable '$a_variable); 
    
$template_hook['some_hook'] .= $templater->render(); 

or - using a variable (which must then be registered for us in the next template):
PHP Code:

    $templater vB_Template::create('my_custom_template'); 
        
$templater->register('a_variable '$a_variable);
    
$somevariable .= $templater->render(); 

or - print_output:
PHP Code:

    $templater vB_Template::create('my_custom_template'); 
        
$templater->register('a_variable '$a_variable);
    
print_output($templater->render()); 

There is a blog entry by Kier over on vb.com that shows this.

I'm not a coder or anything, but I do require certain small plugins that would most likely be only useful for me. I have played with these examples, as well as ones previously provided on vBulletin.com, but have failed to wrap my head around how it is actually supposed to work. In my case, I simply need to be able to use a custom variable containing data in templates. One simple example of this would be as follows:
PHP Code:

$random_number rand(1105); 

How exactly should the plugin be formulated to make the variable $random_number accessible in the header template?

Omegatron 11-16-2009 09:23 AM

well your plugin would hook where ever you wish and to access the variable in the header template it would be something like this

{vb:raw random_number}

--------------- Added [DATE]1258370775[/DATE] at [TIME]1258370775[/TIME] ---------------

Lynne thanks I posted there because its a huge design flaw in the new system IMO. I added my own hook name and it works fine but using the str_replace or something is needed I think because the whole point of the plugin system is to NOT make hand edits to files templates etc.

anyway here is the code I posted using etc


Template question for plugins.

Now say for instance I want to show a block of info on forumhome. I know I can do this since the template_hook is now a super global.

Code:

    $templater = vB_Template::create('forumhome_addon');
    $templater->register_page_templates();
    $templater->register('block_info', $block_info);
    $template_hook['navbar_end'] .= $templater->render();

That works fine prints the block at the end of the navbar and everything is fine. But I dont want it there. See in vb3 you did a fetch_template and str_replace on the $navbar variable and added your template under so it showed up before your forum list. This is what I want to be able to add a block of info before the $forumbits. Nothing I do a str_replace on works because there is no hook there. The plugin is at forumhome_complete and this does not work

Code:


    $templater = vB_Template::create('forumhome_addon');
    $templater->register_page_templates();
    $templater->register('block_info', $block_info);
    $thistemplater = $templater->render();
   
    $search_text = '<div id=\"pagetitle\">';
    $vbulletin->templatecache['FORUMHOME'] = str_replace($search_text,$thistemplater.$search_text,$vbulletin->templatecache['FORUMHOME']);

I have tried doing a str_replace for that div tag or forumbits etc. Anyone have any hints on how to get it to work where I want it. Like I said it works fine if like add my new template into the actual template hook but thats the wrong location. There is no hook it seems at the top of the forum which IMO is an oversight on IB's part since in vb3 the top of the forumhome was right after $navbar and now it isnt

Pitman 11-16-2009 09:43 AM

Quote:

Originally Posted by Omegatron (Post 1915136)
well your plugin would hook where ever you wish and to access the variable in the header template it would be something like this

{vb:raw random_number}

Well, I understand that much of it, but I'm not sure about how to go about formatting the plugin and registering the variable in the way that I need to. Any way that I've tried to register the variable in the provided examples I've seen anywhere have proved to be ineffective. I understand how to use the variable in the templates, but I'm unsure of how to correctly register the variable in the plugin while effectively being able to use {vb:raw random_number} in a specific and already available template.

Furthermore, while providing more information, in the following example:
PHP Code:

    $templater vB_Template::create('my_custom_template'); 
        
$templater->register('a_variable '$a_variable);
    
$somevariable .= $templater->render(); 

I only understand the $templater->register('a_variable ', $a_variable); there. Being that I'm not creating a template, the first line of code makes no sense to me. I also do not understand the render code or what I should use there either.

Paul M 11-16-2009 10:34 AM

Quote:

Originally Posted by Omegatron (Post 1915136)
Lynne thanks I posted there because its a huge design flaw in the new system IMO.

What design flaw do you mean exactly ?

Omegatron 11-16-2009 10:52 AM

Well if you can no longer display a block before the forumbits because you can not longer do a str_replace and there is not a hook for there its a design flaw. I do not beleive the point of vb4 was to go backwards from vb3 in the plugin system. if vb is going to make the only way you can include a template is through the hook system since its a superglobal then they need to do hooks everywhere. The whole purpose of the plugin system is to keep you from having to hack vb files templates.

i did what I needed to do by creating a new template hook name and editing the forumhome template to include the template hook where i wanted it. Remember in vb3 how alot of hacks appeared right before the forumbits or right after. there are no hook locations in forumhome other than in who's online. In vb3 you just did a str_replace to print your template right after the navbar. So if you can not longer do a str_replace and have to use a hook instead and there are non then its a design flaw especially somewhere as prized a location as the top of bottom of the forumbits. Just my Opinion ;)

--------------- Added [DATE]1258376073[/DATE] at [TIME]1258376073[/TIME] ---------------

Pitman

You need to register any variables for use in a template. The initial post in this thread by lynne gives examples ;)

ragtek 11-16-2009 10:59 AM

I think there's now a way to preRegister the variables, so as i understood it, you'll need no more str_replace ;)

I hope realy that there will be some great articles for vB4.
The best way would be, if some vbulletin developers would write articles, because they could show "us" the best way to extend vB4

Yellow Slider 11-16-2009 11:48 AM

Quote:

Originally Posted by Lynne (Post 1914741)
a_variable is the name of the variable you are registering. $tagforms was supposed to be $a_variable, but I forgot to change it - it is now changed. As for the $template_hook, that would be the name of the template_hook you are trying to use.... if you are using a template_hook. I gave several examples up there - you would not use them all for one template call.

Unfortunately, it still doesn't work for me.
For example, if i want to use the template_hook method, and my template name is abc, my var name is var, and i want to use it in the forumhome template, the code should be something like this?
PHP Code:

    $templater vB_Template::create('abc'); 
        
$templater->register('var '$var); 
    
$template_hook['forumhome'] .= $templater->render(); 


Shadab 11-16-2009 12:13 PM

@Yellow Slider:

If I understand correctly, you want to evaluate the template "abc"
and make the result available in the FORUMHOME template via the variable "var" ?

Yellow Slider 11-16-2009 12:20 PM

Quote:

Originally Posted by Shadab (Post 1915208)
@Yellow Slider:

If I understand correctly, you want to evaluate the template "abc"
and make the result available in the FORUMHOME template via the variable "var" ?

Yes.


All times are GMT. The time now is 12:57 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.01146 seconds
  • Memory Usage 1,770KB
  • 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
  • (2)bbcode_code_printable
  • (6)bbcode_php_printable
  • (6)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete