Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-11-2012, 07:03 PM
MyLibary MyLibary is offline
 
Join Date: May 2011
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Make custom templates and call it with "vb:raw"

Hello all,

Im trying to make some custom template for example i have created template name:
custom_header_mysite_beta

and i would like to use the content in this code in aother template, for example at header template in the next way:

{vb:raw ad_location.global_header1}

In my case:

{vb:raw custom_header_mysite_beta}

How can i do that?
Reply With Quote
  #2  
Old 05-11-2012, 07:43 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need to create a plugin, render your template, and preRegister the result to the header template. Hook location parse_templates is a good one to use, and the code could be like:

Code:
$template = vB_Template::create('custom_header_mysite_beta');
$customheader = $template->render();
vB_Template::preRegister('header', array('custom_header_mysite_beta' => $customheader));
Reply With Quote
  #3  
Old 05-11-2012, 07:54 PM
MyLibary MyLibary is offline
 
Join Date: May 2011
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I just take it exactly like it is and paste it in a new plugin?
How should i name the plugin?

Once i have done it template will be created and i will be able to use this code:
{vb:raw custom_header_mysite_beta}

in the header?

Thanks alot!
Reply With Quote
  #4  
Old 05-11-2012, 07:56 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MyLibary View Post
I just take it exactly like it is and paste it in a new plugin?
How should i name the plugin?
Yes, you should be able to copy and paste that code. You can name the plugin anything you want - name it something so that years from now when you wonder what it is, the title might give you some idea .


Quote:
Once i have done it template will be created and i will be able to use this code:
{vb:raw custom_header_mysite_beta}

in the header?
Yes, that should work.
Reply With Quote
  #5  
Old 05-11-2012, 08:02 PM
MyLibary MyLibary is offline
 
Join Date: May 2011
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

May i ask what the last row mean?
vB_Template:reRegister('header', array('custom_header_mysite_beta' => $customheader));

What is that $customheader and what if i change it to something else?
Reply With Quote
  #6  
Old 05-11-2012, 08:06 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MyLibary View Post
May i ask what the last row mean?
vB_Template:reRegister('header', array('custom_header_mysite_beta' => $customheader));
Before you can use something like {vb:raw custom_header_mysite_beta} in a template, you must register (or preRegister) a value for custom_header_mysite_beta. There's an article describing this process here: https://vborg.vbsupport.ru/showthread.php?t=228078 (Sorry, I probably should have sent you to that article first).


Quote:
What is that $customheader and what if i change it to something else?
You can change it to whatever you want as long as you change it on the line above as well. The point is that the result of render() is what is registered to custom_header_mysite_beta. ($customheader is just a temporary variable).
Reply With Quote
  #7  
Old 05-11-2012, 08:10 PM
MyLibary MyLibary is offline
 
Join Date: May 2011
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Works great!

Do i have limit of how much plugins like that i can create?
Or in other words will it slow my website if i will create up to 20 custom plugins like this?

Thanks alot for your time and your help!
Reply With Quote
  #8  
Old 05-11-2012, 08:15 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MyLibary View Post
Do i have limit of how much plugins like that i can create?
Or in other words will it slow my website if i will create up to 20 custom plugins like this?
I don't think it matters how many plugins you have since all the code for a given hook location gets built in to one string and loaded from the datastore in one call. But unless you have a reason to want to keep them separate, there's no reason you couldn't do it all in one plugin.

You can also use one preRegister call (assuming they're all going to the header template), like:

Code:
$template = vB_Template::create('template1');
$templatevalues['template1'] = $template->render();

$template = vB_Template::create('template2');
$templatevalues['template2'] = $template->render();

$template = vB_Template::create('template3');
$templatevalues['template3'] = $template->render();

vB_Template::preRegister('header', $templatevalues);

But if you'd rather make them separate, I don't think there's a lot of overhead involved in multiple plugins or preRegister calls.
Reply With Quote
  #9  
Old 05-11-2012, 08:23 PM
MyLibary MyLibary is offline
 
Join Date: May 2011
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So you say i can do something like this in the same plugin right?

Code:
$template = vB_Template::create('custom_header_mysite_beta1');
$customheader1 = $template->render();
vB_Template::preRegister('header', array('custom_header_mysite_beta1' => $customheader1));

$template = vB_Template::create('custom_header_mysite_beta2');
$customheader2 = $template->render();
vB_Template::preRegister('footer', array('custom_header_mysite_beta2' => $customheader2));

$template = vB_Template::create('custom_header_mysite_beta3');
$customheader3 = $template->render();
vB_Template::preRegister('headerinclude', array('custom_header_mysite_beta3' => $customheader3));
And if i use this string you suggested

should i call in this way:

{vb:raw template1}
{vb:raw template2}
{vb:raw template3}

?

Thanks alot for you kind help!!
Reply With Quote
  #10  
Old 05-11-2012, 08:31 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MyLibary View Post
So you say i can do something like this in the same plugin right?
Yes, that code looks OK to me.


Quote:
And if i use this string you suggested

should i call in this way:

{vb:raw template1}
{vb:raw template2}
{vb:raw template3}

?

Yes, if you were to use the example code I posted above. The array key is what you use in the vb:raw tag.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:40 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.04515 seconds
  • Memory Usage 2,256KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (7)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete