vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   [HOW TO - vB4] Rendering templates and registering variables - a short guide (https://vborg.vbsupport.ru/showthread.php?t=228078)

cellarius 10-09-2010 05:47 AM

You need to find out in the php files where the quickchooserbits and languagechooserbits variables are filled; they also will be registered for the footer template there. Then you need to find a hook that's executed afterwards and register those two variables for the template you want to put it in.

Vikingant 10-09-2010 09:23 PM

Quote:

Originally Posted by cellarius (Post 2108329)
You need to find out in the php files where the quickchooserbits and languagechooserbits variables are filled; they also will be registered for the footer template there. Then you need to find a hook that's executed afterwards and register those two variables for the template you want to put it in.

Thank you cellarius
Does this come in english? O.o
Sorry, but I am VERY new to all of this due to necessity and am not familiar with some of the terminology yet.
Where do I look for the PHP files? How do I register variables? How do I find/register a hook?

cellarius 10-10-2010 03:37 PM

The php files (among other stuff) is what you upload to your webspace. How to register variables for templates is what this tutorial is all about, but if you don't have at least basic knowledge of php this may be difficult to do.

Some basics about the vB addon/plugin system can be found here:
http://www.vbulletin.com/docs/html/

Vikingant 10-14-2010 11:59 AM

Thanks for that. I may be getting over excited with wanting to do stuff now that I can. I will definately read up some more. I have found (bluffed) my way through a lot relatively unscathed so far.

Quick hint: Do I look int the FTP or ACP?

Ta

cellarius 10-14-2010 01:23 PM

PHP files you find via FTP, plugins and addons you handle via AdminCP.

Duncan 10-25-2010 05:56 AM

I am using a custom page and it works properly. However, I have listed on the custom page in the style editor {vb:raw navbar2}. I want the template to display what is in my navbar2 style.

This is in the php file for the custom page:

$templater = vB_Template::create('ncsu');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('navbar2', $navbar2);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());

And it is still not recognizing {vb:raw navbar2}. Should I add something about this? If so, what? Thank you!

kurv 11-04-2010 05:08 AM

Okay guys, I have read the entire thread and my apologies for my coding ignorance. What I am trying to do is, use a different navbar template on the forumdisplay pages than on the home page.

So I added a new template, called navbarforumdisplay

Copied the code from the navbar template into navbarforumdisplay and removed the items I added in the forumhome version that I don't want appearing in the forumdisplay (only items I added to begin with, not vB code :) ).

Then after reading this thread, I created a plugin here

Title: Forumdisplay Navbar
Hook Location: forumdisplay_complete
Exc Order: 5

with the following code
Code:

global $template_hook;
$newTemplate = vB_Template::create('navbarforumdisplay');
$template_hook['fd_navbar'] .= $newTemplate->render()

Then I added the following code to the FORUMDISPLAY template

Code:

{vb:raw fd_navbar}
and removed
Code:

{vb:raw navbar}
Can someone tell me what I am doing wrong, or what is the best way to do this?

Thank you!!!

ROTPAR 11-06-2010 11:34 AM

could anybody please give me a step by step tutorial, how to make this code work in postbit_legacy?

PHP Code:

<vb:if condition="$show['fb_likebutton']">
            {
vb:raw fblikebutton}
        </
vb:if> 


cellarius 11-07-2010 08:50 PM

Quote:

Originally Posted by kurv (Post 2117765)
...

Waaaay too complicated. Go to the normal navbar template and put everything you do not want to appear on forumdisplay inside this condition:
Code:

<vb:if condition="THIS_SCRIPT != 'forumdisplay'">code not to be shown on forumdisplay</vb:if>

StarBuG 11-13-2010 07:39 AM

Hello. I need your help.

I need the $pagenumber variable to be available in postbit_legacy so that I can create an url when the thread has multiple pages.

Currently I am using: <a href="http://www.patientenfragen.net/{vb:link thread, {vb:raw thread}}" target="_blank">

but I need it to work this way:

<a href="http://www.patientenfragen.net/{vb:link thread, {vb:raw thread}<vb:if condition="$pagenumber">&amp;page={vb:raw pagenumber}</vb:if>}" target="_blank">

I need the url including the page the user is on.

I am no programmer so even though your explanation is quite detailed I don't really get what I have to do.
I need to register that variable to the postbit_legacy template, but how do I do that?

Sorry for asking such a stupid question but I am totally lost here.

Any help is much appreciated.

StarBuG

Hippy 11-22-2010 09:55 PM

thanks for the time and effort spent on this article

very helpfull

KaiStone 01-01-2011 06:09 PM

Please help me with this issue.

I have a plug in (Location: parse_templates)

Code:

if($vbulletin->options['enable_vbadv'] AND in_array($vbulletin->userinfo['usergroupid'], explode(',', $vbulletin->options['vbadv_ug'])))
                        {
                                        switch($vbulletin->options['vbadv_place'])
                                {
                                        case 1:
                                                $place = '$navbar';
                                                $fechttemplate = 'FORUMHOME';
                                                break;
                                        case 2:
                                                $place = '$ad_location[ad_navbar_below]';
                                                $fechttemplate = 'navbar';
                                                break;
                                        default:
                                                $place = '$navbar';
                                                $fechttemplate = 'FORUMHOME';
                                                break;
                                }
                        $vbulletin->templatecache[$fechttemplate] = str_replace($place, $place . '\n' . fetch_template('forumhome_+++++++_com_adv'), $vbulletin->templatecache[$fechttemplate]);
                        }



I've tried to fix it like this

Code:

if($vbulletin->options['enable_vbadv'] AND in_array($vbulletin->userinfo['usergroupid'], explode(',', $vbulletin->options['vbadv_ug'])))
                        {
        $templater = vB_Template::create('forumhome_+++++++_com_adv');
        $templater->register('advheader', $advheader);
        $advheader = $templater->render();
                                        switch($vbulletin->options['vbadv_place'])
                                {
                                        case 1: $template_hook['forumhome_above_forums'] .= $advheader; break;
                                        case 2: $ad_location['global_below_navbar'] .= $advheader; break;
                                }
                        }

But it takes effect only when I choose case 1, display below forums. When I choose "Below Navbar", there's nothing displayed. Please help me to fix it.

Thank you very much, and sorry for my bad English.

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

It's Fixed. Just simple change Location to "global_start"

TheInsaneManiac 01-03-2011 03:48 PM

All I want to do is covert the current fetch template into current VB code. How do I do this in 4.0?
Code:

eval('$soundnotification = "' . fetch_template('sound_notification') . '";');
I tried:
Code:

$soundnotification .= vB_Template::create('sound_notification')->render();
But to no avail does it work

rob01 01-05-2011 05:52 PM

is posible to do

{vb:raw my_var.userid}

or how i should call for the user id or username?

for example vb3:

<br>User Registration IP Address: $spammerinfo[ipaddress]
<br>User IP Address for Selected Post: $postinfo[ipaddress]

but how to make it work for vb4?
:S

KaiStone 01-06-2011 11:20 AM

Quote:

Originally Posted by rob01 (Post 2144523)
is posible to do

{vb:raw my_var.userid}

or how i should call for the user id or username?

for example vb3:

<br>User Registration IP Address: $spammerinfo[ipaddress]
<br>User IP Address for Selected Post: $postinfo[ipaddress]

but how to make it work for vb4?
:S

As my knowledge, if in vB3, the command is $spammerinfo[ipaddress] and $postinfo[ipaddress], so in vB4, the command is

{vb:raw spammerinfo.ipaddress}
{vb:raw postinfo.ipaddress}

rob01 01-07-2011 12:18 AM

uhmm yeah, but the problem is that spammerinfo attribute is not working :S

Lynne 01-07-2011 01:27 AM

Quote:

Originally Posted by rob01 (Post 2145208)
uhmm yeah, but the problem is that spammerinfo attribute is not working :S

Did you register the variable for use in that template?

TheInsaneManiac 01-08-2011 12:18 AM

Quote:

Originally Posted by TheInsaneManiac (Post 2143389)
All I want to do is covert the current fetch template into current VB code. How do I do this in 4.0?
Code:

eval('$soundnotification = "' . fetch_template('sound_notification') . '";');
I tried:
Code:

$soundnotification .= vB_Template::create('sound_notification')->render();
But to no avail does it work

Help

Yaung Sein 01-09-2011 02:20 AM

I want to register $forum in facebook_publishcheckbox template. But I don't know where I set those set those register value in what file.

PHP Code:

vB_Template::preRegister('facebook_publishcheckbox',array('forum' => $forum)); 


facebook_publishcheckbox Template
Code:

<label id="fb_pulishlabel" for="fb_dopublish">
        <img src="{vb:stylevar imgdir_misc}/facebook.gif" alt="{vb:rawphrase publish_to_facebook}" />
        {vb:rawphrase publish_to_facebook}
        <input type="checkbox" tabindex="1" id="fb_dopublish" value="1" <vb:if condition="in_array($forum['forumid'], array(70,80,81,82,83,88,92,93))"><vb:else />checked="checked" </vb:if>name="fb_dopublish" />
</label>

Please help me, I am a very beginner.

KaiStone 01-13-2011 11:05 AM

Put the register code in a plugin, and call it where your template displays (by choosing hook location). In the case you don't really know what to do, Creat a new plugin and choose hook location is global_start or parse_template

TheInsaneManiac 02-06-2011 04:16 AM

Quote:

Originally Posted by ckgreenman (Post 2031248)
Hello, I hope someone can point in the right direction. I'm trying to port a mod to vb4 which has a number of templates. The php file contains a whole bunch of
Code:

eval('$template .= "' . fetch_template('templatename') . '";');
lines. The mod uses a main template which then calls the other templates from within the main template using $template references to the other templates.

I've tried a number of different iterations form the first post but I can't get anything but the main template to render. How does one go about making something like this work?


thanks.

Im wondering the same thing.

wonderfulwat 03-05-2011 07:07 AM

I've created a custom template "memberaction_dropdown_one" which I want to have show up in another custom template "postbit1".

Please help show me how to declare this. If anyone has skype it would be very much appreciated if you could walk me through the process in realtime (probably 5 min max). Send me a PM.

brandondrury 03-07-2011 08:03 PM

Just out of curiosity, is there any reason why this wouldn't work in vB 4.1.1? I'm getting some unexpected errors and wanted to rule out that element before I dig TOO deep.

Brandon

cellarius 03-11-2011 03:50 PM

Quote:

Originally Posted by brandondrury (Post 2170667)
Just out of curiosity, is there any reason why this wouldn't work in vB 4.1.1?

No, none that I'm aware of. This is pretty basic vB4 architecture, and nothing did change there.

Phaedrus 03-18-2011 07:51 AM

This is where one of those "thank you" mods would come in handy. This was a lifesaver, I was able to upgrade a mod that I needed for any upgrade.

ninadbe 03-23-2011 04:47 PM

Is there any way to make plugin that uses remote database connection or use to extract data from other server?
We have vbulletin forum for our site, but our site is located on one server and forum located on another server in order to avoid load.
I want to extract data from main site (which is located on another server) and display it on forum.

I tried lot , searched everywhere. But I not found any specific plugin / mod.

I created custom plugin on my own but it giving errors like
"MySql client ran out of memory"
"Invalid key error"

cellarius 03-23-2011 05:44 PM

This is question has nothing to do with the article this discussion thread is for. Please open your own thread in an appropriate forum.

TalkVirginia 04-01-2011 06:29 AM

I'm trying to capture a rendered/parsed template to a variable like so:

PHP Code:


$templater 
vB_Template::create('test');
$templater->register('userid'$userid);
$templater->register('bbtitle'$bbtitle);
$templater->register('homeurl'$homeurl);
$templater->register('forumurl'$forumurl);
$myvar $templater->render(); 

echo 
$myvar

I would expect that myvar would contain the parsed template, but it comes up empty.

Can anyone help me?

gibigbig 04-02-2011 05:48 AM

using in a mod:

1) make a new plugin
Hook: global_start
code:
PHP Code:

$template_hook['footer_javascript'] .= '<b>HTML goes here</b>'

spent a good few hours looking for how to do such a simple task this article has way over complicated.
also, tested and working in vb 4.1.2


also note that you can even make your own hook by using the code:
HTML Code:

{vb:raw template_hook.hook_name}
in any template
simple stuff.

cellarius 04-02-2011 06:05 AM

Quote:

Originally Posted by gibigbig (Post 2180012)
using in a mod:

1) make a new plugin
Hook: global_start
code:
PHP Code:

$template_hook['footer_javascript'] .= '<b>HTML goes here</b>'

spent a good few hours looking for how to do such a simple task this article has way over complicated.
also, tested and working in vb 4.1.2

Sorry that my article turned out to be too complicated for you. If you don't want to render a template, it may have not been made for you. Anyway - leave the template rendering aside, and you have exactly your line of code at the end of the code that covers template hooks.

By the way: hook global_start is not a good choice. It does not exist in the CMS and will vanish from any part of the product that gets rewritten to the OOP framework in future.

Boofo 04-02-2011 06:12 AM

Quote:

Originally Posted by TalkVirginia (Post 2179676)
I'm trying to capture a rendered/parsed template to a variable like so:

PHP Code:


$templater 
vB_Template::create('test');
$templater->register('userid'$userid);
$templater->register('bbtitle'$bbtitle);
$templater->register('homeurl'$homeurl);
$templater->register('forumurl'$forumurl);
$myvar $templater->render(); 

echo 
$myvar

I would expect that myvar would contain the parsed template, but it comes up empty.

Can anyone help me?

This:

Code:

$myvar = $templater->render();

should be this:

Code:

$myvar .= $templater->render();

rlarner 04-05-2011 07:49 PM

I'm struggling with getting data from a variable into one of the stock templates. Here's what I've done:
Created a custom plugin with the hook location set to "global_start":
$roscohtml = "<div>HELLO WORLD!</div>";
error_log($roscohtml);
vB_Template::preRegister('header',array('roscohtml '=>$roscohtml));

Then I customized the header template to contain this:
<div class="above_body"> <!-- closing tag is in template navbar -->
<div>test before</div>
{vb:raw roscohtml}
<div>test after</div>

Unfortunately the variable isn't being output. I do see the contents in the error log, so I know it's firing.

Any tips?

Thanks,
Rosco

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

OK, I think I found the problem - the global_start hook is not the right place for this to live. I moved my code to the parse_templates hook and the data is now available.

Is there a document which outlines the best way to leverage the hooks, or at least where each is called in the flow?

Rosco

bela-meaad 04-25-2011 06:42 PM

as templates no longer get output using eval
i tried to change it but seems not working.

can anyone help me with this code?


PHP Code:

if ($vbulletin->options['card_onoff'] AND THIS_SCRIPT != 'private' AND THIS_SCRIPT != 'login')
{
if( 
$vbulletin->userinfo['usergroupid']!=OR $vbulletin->userinfo['usergroupid']!=OR $vbulletin->userinfo['usergroupid']!=)
{
    
$istherewinner=mysql_query("SELECT `value` FROM `setting` WHERE `varname` = 'card_carintwin' LIMIT 1");
    while (
$yeswinner $db->fetch_array($istherewinner))
{
    
$bigwinner =$yeswinner[value];
}

if(
$bigwinner)
{
    eval(
'$card_win_index = "' fetch_template('card_win_index') . '";');
    
$ad_location['global_below_navbar'] .= $card_win_index;
}
else
{
    eval(
'$card_index = "' fetch_template('index_card') . '";');
    
$ad_location['global_below_navbar'] .= $card_index;
}
}



Boofo 05-07-2011 02:48 PM

<a href="https://vborg.vbsupport.ru/showpost.php?p=2180014&postcount=151" target="_blank">https://vborg.vbsupport.ru/showp...&postcount=151</a>

BirdOPrey5 07-05-2011 07:09 PM

I hoping this isn't too far off topic bt if possible I think it would make a good addition to the article...

What if I want to override an existing template with a new template. Basically ignore whatever is in a given template and render a new template, and copy the new template to the old template? Is that possible?

I've tried stuff like:

Code:

$templater = vB_Template::create('my_new_template');
$templater->register('myvar', $myvar);
$globaltemplates['existing_vb_template'] = $templater->render();

in all the various template hooks to no avail. I've also tried using $vbulletin->templatecache['existing_vb_template'] in the last line instead of $globaltemplates and also did not work.

Is what I'm asking possible? Seems like it should be... Any input would be appreciated.

Boofo 07-05-2011 07:58 PM

Yes, it can be done easily, if what you are wanting is what I understand it to be. As an example, here is what I did for that:

Code:

$templater = vB_Template::create('boofo_forumhome_event');
    $templater->register('callink', $callink);
    $templater->register('daysevents', $daysevents);
    $templater->register('eventdate', $eventdate);
    $templater->register('eventdates', $eventdates);
$upcomingevents .= $templater->render();

$vbulletin->templatecache['forumhome_event'] = $vbulletin->templatecache['boofo_forumhome_event'];


BirdOPrey5 07-05-2011 09:40 PM

Great, Thanks Boofo!

It might be worth mentioning for anyone else- you have to register any variables used to the ORIGINAL template (the one you are overriding) not the new template... At least that's the only way it's working for me. (On parse_templates hook)

Boofo 07-05-2011 10:12 PM

Are you sure? I used the same variables when I did it but I would think you only need to pre-register the variables you are going to use, not the other way around.

I did the above code in forumhome_start. Did you try the process_templates_complete hook?

BirdOPrey5 07-06-2011 12:34 AM

Maybe I didn't explain it right... in your example registering callink and the others to boofo_forumhome_event didn't do anything for me- I had to preRegister them to forumhome_event for them to work. I tried both parse_templates and process_templates_complete hooks.

To me it makes sense since the forum thinks it's outputting forumhome_event, and this is confirmed by viewing template names in the HTML source code.

Boofo 07-06-2011 12:53 AM

Well, yes and no. Since I did it in the forumhome_start hook, it needed those pre-registered for my new template. As long as the variables are good at that hook, then it will work the way I did it.

The forumhome doesn't care about the old template as long as I pre-register everything for my new template. Doing it in the parse_templates hook might be why it didn't work for you with your code. You would have to check whether whatever variables you are pre-registering have already been validated at whatever hook you are using.

Now I'm getting confused. And it hurts! LOL


All times are GMT. The time now is 04:20 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.02078 seconds
  • Memory Usage 1,886KB
  • 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
  • (16)bbcode_code_printable
  • (1)bbcode_html_printable
  • (7)bbcode_php_printable
  • (9)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)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