vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Make custom templates and call it with "vb:raw" (https://vborg.vbsupport.ru/showthread.php?t=282796)

MyLibary 05-11-2012 07:03 PM

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?

kh99 05-11-2012 07:43 PM

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));


MyLibary 05-11-2012 07:54 PM

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!

kh99 05-11-2012 07:56 PM

Quote:

Originally Posted by MyLibary (Post 2328535)
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.

MyLibary 05-11-2012 08:02 PM

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

What is that $customheader and what if i change it to something else?

kh99 05-11-2012 08:06 PM

Quote:

Originally Posted by MyLibary (Post 2328541)
May i ask what the last row mean?
vB_Template::preRegister('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).

MyLibary 05-11-2012 08:10 PM

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!

kh99 05-11-2012 08:15 PM

Quote:

Originally Posted by MyLibary (Post 2328547)
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.

MyLibary 05-11-2012 08:23 PM

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!!

kh99 05-11-2012 08:31 PM

Quote:

Originally Posted by MyLibary (Post 2328551)
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.


All times are GMT. The time now is 01: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.01097 seconds
  • Memory Usage 1,748KB
  • 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
  • (7)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)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