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)

kh99 01-08-2012 07:21 PM

If you switch the template names (just for a test), does it still only work in the navbar?

HMBeaty 01-08-2012 11:44 PM

1 Attachment(s)
Still not working, here is the complete code in use atm...

(code removed :))

kh99 01-09-2012 12:02 AM

Quote:

Originally Posted by HMBeaty (Post 2285396)
... the variable I'm trying to use in the header is {vb.raw navnet}, but it doesn't show anything but the raw variable...

Oh, that's different, I thought you were seeing nothing. But I think it's just that it should be vb:raw instead of vb.raw (I totally missed that in your above post).

HMBeaty 01-09-2012 01:35 AM

Quote:

Originally Posted by kh99 (Post 2285401)
Oh, that's different, I thought you were seeing nothing. But I think it's just that it should be vb:raw instead of vb.raw (I totally missed that in your above post).

Lmao, wow! It was definately ":" instead of ".". I can't believe I did that :o. Thanks. [S]On a side note, any idea as to how to adjust the position of a Google+ button? I've been at it for several hours, and it just doesn't seem to move :confused:[/S] Figured that out finally :p

TheSupportForum 01-13-2012 03:29 AM

i need help parsing a code into HEADER template using plugin

basically i need to insert a code after

Code:

<div id="toplinks" class="toplinks">
i dont want a template, i just want the plugin to insert a code directly after that shown above

using something like

Code:


$find <div id="toplinks" class="toplinks">
$mycode <div style="float:right; margin: 5px -12px 5px 10px;">{vb:raw mycode </div>

i am not sure the rest but i know its something like that

Boofo 01-13-2012 03:44 AM

Try this in the parse_templates hook:

Code:

require_once(DIR . '/includes/class_template_parser.php');
$parser = new vB_TemplateParser('<div id="toplinks" class="toplinks">');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$find = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$parser = new vB_TemplateParser('<div style="float:right; margin: 5px -12px 5px 10px;">{vb:raw mycode}</div>');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$replace = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$vbulletin->templatecache['header'] = str_replace($find, $find . $replace, $vbulletin->templatecache['header']);
unset($find, $replace);


TheSupportForum 01-13-2012 03:55 AM

Quote:

Originally Posted by Boofo (Post 2287132)
Try this in the parse_templates hook:

Code:

require_once(DIR . '/includes/class_template_parser.php');
$parser = new vB_TemplateParser('<div id="toplinks" class="toplinks">');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$find = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$parser = new vB_TemplateParser('<div style="float:right; margin: 5px -12px 5px 10px;">{vb:raw mycode}</div>');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$replace = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$vbulletin->templatecache['header'] = str_replace($find, $find . $replace, $vbulletin->templatecache['header']);
unset($find, $replace);



I thank you very much it worked 100% :)

updating templates this way works perfect without the need to go into the template to manually input it
thx

Boofo 01-13-2012 04:01 AM

Quote:

Originally Posted by simonhind (Post 2287137)
I thank you very much it worked 100% :)

updating templates this way works perfect without the need to go into the template to manually input it
thx

You actually had doubts it would work? ;)

TheSupportForum 01-13-2012 04:17 AM

Quote:

Originally Posted by Boofo (Post 2287142)
You actually had doubts it would work? ;)

lol, i have lost touch with vb coding in a long time, i just need to get used to it, plus i am glad you repsonded i have seen your great work and advice on here
many thanks

Boofo 01-13-2012 04:42 AM

Quote:

Originally Posted by simonhind (Post 2287145)
lol, i have lost touch with vb coding in a long time, i just need to get used to it, plus i am glad you repsonded i have seen your great work and advice on here
many thanks

vb 4 handles str_replace differently, for some reason. Glad I could help. ;)

HMBeaty 01-13-2012 05:55 AM

Quote:

Originally Posted by Boofo (Post 2287132)
Try this in the parse_templates hook:

Code:

require_once(DIR . '/includes/class_template_parser.php');
$parser = new vB_TemplateParser('<div id="toplinks" class="toplinks">');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$find = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$parser = new vB_TemplateParser('<div style="float:right; margin: 5px -12px 5px 10px;">{vb:raw mycode}</div>');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$replace = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$vbulletin->templatecache['header'] = str_replace($find, $find . $replace, $vbulletin->templatecache['header']);
unset($find, $replace);


I can't say I've ever seen this done :eek: I might have to use this in the future :D

Boofo 01-13-2012 06:34 AM

Go for it. An unnamed dev gave it to me a long while back.

clubvr4 02-23-2012 06:18 PM

Hey all,

I think i'm being really dumb here, looking for some help.

In my Navbar Template i want to call another template that i want to create, rather that adding code irectly into the navbar template.

Am i right in thinking that i have to register the code in a php file on the server, or can i do this all via a plug in and templates? if so, does anyone have some code for a simple example, i.e. call 1 new template from within another VB default template? - I ask because unless i am mistaken what i've read thus far seems to focus more on adding code to PHP files.

Currently running 4.1.10.

The template I want to call from navbar template is called memberbar_basic.

kh99 02-25-2012 11:26 PM

Quote:

Originally Posted by clubvr4 (Post 2302738)
The template I want to call from navbar template is called memberbar_basic.

You would create a new plugin with code something like this:

Code:

$templater = vB_Template::create('memberbar_basic');
$templater->register('my_var', $my_var); // one or more of these if memberbar_basic uses variables, otherwise leave it out.
$memberbar_basic = $templater->render();
vB_Template::preRegister('navbar', array('memberbar_basic' => $memberbar_basic));


and you would put {vb:raw memberbar_basic} in the navber template. Hook location parse_templates would probably be a good place for your plugin.

clubvr4 02-27-2012 09:20 AM

Hiya,

Thanks for responding - I can't seem to get it to work though, let me review whats currently configured.

Template = memberbar_member_basic
Template content = memberbar member basic test.

Plugin name = memberbar_member_basic
Plugin Hook = Parse Templates
Plugin Content =
PHP Code:

$templater vB_Template::create('memberbar_member_basic');
$memberbar_member_basic $templater->render();
vB_Template::preRegister('navbar', array('memberbar_member_basic' => $memberbar_member_basic)); 

Navbar Template (at bottom) i've placed - {vb:raw memberbar_member_basic}

I tried moving {vb:raw memberbar_member_basic} to other templates, specifically forumhome but its still not rendering.

would i have to use variables? if so, is there a guide/overview of what variables would bee needed anywhere?

Thanks
B

BirdOPrey5 02-27-2012 09:24 AM

Off hand there's a typo in the middle line, it's missing the first "m" in "memberbar"

If that error is in your real code it wouldn't work.

clubvr4 02-27-2012 01:04 PM

haha, now i do really feel stupid....

ok, modified my thread correcting the typo and im please to say its working!..

/grabs coat..

(p.s. thank you!)

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

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

Progressing from my previous query.

I need to register some variables to allow notifications to be registered in my plugin (Post # 216)

I've tried following this guide here..

https://www.vbulletin.com/forum/show...ons-menu-place

I attempted the following, to no avail.

Plugin name = memberbar_member_basic
Plugin Hook = Parse Templates
Plugin Content =
PHP Code:

$templater vB_Template::create('memberbar_member_basic');
$memberbar_member_basic $templater->render();vB_Template::preRegister('navbar', array('notifications_menubits' => $notifications_menubits));
vB_Template::preRegister('navbar', array('memberbar_member_basic' => $memberbar_member_basic));
vB_Template::preRegister('navbar', array('notifications_menubits' => $notifications_menubits)); 

I then moved the notifications code from header to the memberbar_member_basic template, which for reference makes the dropdown appear but does not show notifications nor total notifications.

Code moved.

PHP Code:

                <vb:if condition="$notifications_total">
                <
li class="popupmenu notifications" id="notifications">
                    <
class="popupctrl" href="usercp.php{vb:raw session.sessionurl_q}">{vb:rawphrase your_notifications}: <span class="notifications-number"><strong>{vb:raw notifications_total}</strong></span></a>
                    <
ul class="popupbody popuphover">
                        {
vb:raw notifications_menubits}
                    </
ul>
                </
li>
                <
vb:else />
                <
li class="popupmenu nonotifications" id="nonotifications">
                    <
class="popupctrl" href="usercp.php{vb:raw session.sessionurl_q}">{vb:rawphrase your_notifications}</a>
                    <
ul class="popupbody popuphover">
                        <
li>{vb:rawphrase no_new_messages}</li>
                        <
li><a href="private.php{vb:raw session.sessionurl_q}">{vb:rawphrase inbox}</a></li>
                    </
ul>
                </
li>
                </
vb:if> 

Basically, what i am trying to achieve is moving the notifications from header to my new template.

Thanks
B

clubvr4 02-28-2012 02:31 PM

Progressing from my previous query.

I need to register some variables to allow notifications to be registered in my plugin (Post # 216)

I've tried following this guide here..

https://www.vbulletin.com/forum/show...ons-menu-place

I attempted the following, to no avail.

Plugin name = memberbar_member_basic
Plugin Hook = Parse Templates
Plugin Content =
PHP Code:

$templater vB_Template::create('memberbar_member_basic');
$memberbar_member_basic $templater->render();vB_Template::preRegister('navbar', array('notifications_menubits' => $notifications_menubits));
vB_Template::preRegister('navbar', array('memberbar_member_basic' => $memberbar_member_basic));
vB_Template::preRegister('navbar', array('notifications_menubits' => $notifications_menubits)); 

I then moved the notifications code from header to the memberbar_member_basic template, which for reference makes the dropdown appear but does not show notifications nor total notifications.

Code moved.

PHP Code:

                <vb:if condition="$notifications_total">
                <
li class="popupmenu notifications" id="notifications">
                    <
class="popupctrl" href="usercp.php{vb:raw session.sessionurl_q}">{vb:rawphrase your_notifications}: <span class="notifications-number"><strong>{vb:raw notifications_total}</strong></span></a>
                    <
ul class="popupbody popuphover">
                        {
vb:raw notifications_menubits}
                    </
ul>
                </
li>
                <
vb:else />
                <
li class="popupmenu nonotifications" id="nonotifications">
                    <
class="popupctrl" href="usercp.php{vb:raw session.sessionurl_q}">{vb:rawphrase your_notifications}</a>
                    <
ul class="popupbody popuphover">
                        <
li>{vb:rawphrase no_new_messages}</li>
                        <
li><a href="private.php{vb:raw session.sessionurl_q}">{vb:rawphrase inbox}</a></li>
                    </
ul>
                </
li>
                </
vb:if> 

Basically, what i am trying to achieve is moving the notifications from header to my new template.

Thanks
B

Easy5s.net 03-23-2012 09:00 AM

OK, I have done.

Preech 04-04-2012 06:04 AM

PHP Code:

$statar $db->query_read("SELECT * FROM " TABLE_PREFIX ." stats"); 

PHP Code:

$templater vB_Template::create('vbmusic');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('statar'$statar);
print_output($templater->render()); 

I understand everything. For some reason, I only get the word Array to show up on my templates. This is what I use on my template.
PHP Code:

{vb:raw statar

I'm guessing I have the array register proper. Is there anything else that I have to add to go with the query. I used the * because their is more than just one result to show from that particular table.

cellarius 04-04-2012 06:25 AM

Well, obviously $statar is an array. I have no idea how you set it up, but just as you can't do echo $array in PHP, you can't just use {vb:raw array}. In PHP you would do echo $array['key'] to output the value. In the template you need to use {vb:raw array.key} accordingly.

Just as described in the first chapter of the article.

Preech 04-05-2012 03:20 PM

Appreciate it Cellarius.
I looked through some of the other vbulletin, so I had to do something like.

while yada yada
{ something = something['']}

And everything started working. Mental error on my part. The only thing now is trying to complete a new mod for vbulletin.

Merriweather 04-22-2012 06:12 PM

If anyone is able to guide me, I am trying to hack the Post Thanks Plugin so I can pass a variable to a template as a conditional.

Here is the function I need to create a conditional for:

PHP Code:

function can_thank_this_post($postinfo = array(), $threadisdeleted 0$check_security false$securitytoken '')
{
    global 
$vbulletin;

    (
$hook vBulletinHook::fetch_hook('post_thanks_function_can_thank_this_post_start')) ? eval($hook) : false;

    if (
$postinfo['postid'] == || $vbulletin->userinfo['userid'] == || $postinfo['isdeleted'] || $threadisdeleted || (!($vbulletin->options['post_thanks_poster_button']) && $postinfo['userid'] == $vbulletin->userinfo['userid']))
    {
        return 
false;
    }

    if (
post_thanks_in_array($vbulletin->userinfo['usergroupid'], $vbulletin->options['post_thanks_usergroup_using']) || post_thanks_in_array($vbulletin->userinfo['userid'], $vbulletin->options['post_thanks_user_useing']))
    {
        return 
false;
    }

    if (
$vbulletin->userinfo['posts'] < $vbulletin->options['post_thanks_post_count_needed'])
    {
        return 
false;
    }

    if (
$vbulletin->options['post_thanks_max_per_day'])
    {
        global 
$count_thanks_so_far_totay;

        if (
$count_thanks_so_far_totay === null)
        {
            
$count_thanks_so_far_totay $vbulletin->db->query_first("SELECT COUNT(*) AS total FROM " .TABLE_PREFIX"post_thanks WHERE userid = " $vbulletin->userinfo['userid'] . " AND date > " . (TIMENOW - (60 60 24)) . "");
        }

        if (
$vbulletin->options['post_thanks_max_per_day'] <= $count_thanks_so_far_totay['total'])
        {
            return 
false;
        }
    }

    if (
$vbulletin->options['post_thanks_days_old'])
    {
        if (
TIMENOW > (($vbulletin->options['post_thanks_days_old'] * 60 60 24) + $postinfo['dateline']))
        {
            return 
false;
        }
    }

    if (
$vbulletin->options['post_groans_integrate'])
    {
        require_once(
DIR '/includes/functions_post_groans.php');
        if (
groaned_already($postinfo))
        {
            return 
false;
        }
    }

    if (
$check_security && function_exists(verify_security_token))
    {
        if (!
verify_security_token($securitytoken$vbulletin->userinfo['securitytoken_raw']))
        {
            return 
false;
        }
    }

    (
$hook vBulletinHook::fetch_hook('post_thanks_function_can_thank_this_post_end')) ? eval($hook) : false;

    return 
true;


And I want to be able to use:

HTML Code:

<vb:if condition="$post['can_thank_post']">Button code here</vb:if>

anupam_luv 04-24-2012 10:37 PM

LW (linkworth ) has given me a php file to include in the navigation bar. It will show rotating ads via rss feed. How can I include that file

I wrote the following code in global_start

PHP Code:


ob_start
();
  include(
'rss_reader.php');
  
$linkmura ob_get_contents();
ob_end_clean();

$templater vB_Template::create('mytemplate');
    
$templater->register('my_var'$linkmura);

$templatevalues['linkmura1'] = $templater->render();
vB_Template::preRegister('navbar'$templatevalues); 

And using {vb:raw linkmura1} to show that. But nothing is been shown (on navbar http://www.dstreetdirect.com )

Also the code in the rss_reader.php is :

PHP Code:


<?php
$insideitem 
false;
$tag "";
$title "";
$description "";
$link ""

function 
startElement($parser$name$attrs)
{
    global 
$insideitem$tag$title$description$link;

    if(
$insideitem)
    {
        
$tag $name;
    }
    elseif(
$name == "ITEM")
    {
        
$insideitem true;
    }
}

function 
endElement($parser$name)
{
    global 
$insideitem$tag$title$description$link;
   
    if (
$name == "ITEM")
    {
        
printf("<dt><b><a href='%s' title='%s'>%s</a></b></dt>",
        
trim($link),htmlspecialchars(trim($description)),htmlspecialchars(trim($title)));
        
printf("<dt>%s</dt><br/><br/>",htmlspecialchars(trim($description)));

        
$title "";
        
$description "";
        
$link "";
        
$insideitem false;
    }
}

function 
characterData($parser$data)
{
    global 
$insideitem$tag$title$description$link;

    if(
$insideitem)
    {
        switch(
$tag)
        {
            case 
"TITLE":
                
$title .= $data;
                break;
            case 
"LINK":
                
$link .= $data;
                break;
            case 
"DESCRIPTION";
                
$description .= $data;
                break;
        }
    }
}

$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");

//====================================================================
//====================================================================
//====================================================================
// ENTER YOUR UNIQUE RSS URL BELOW WHERE YOU SEE THE XXXX's
//====================================================================
//====================================================================
//====================================================================
$fp fopen("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX""r")
   or die(
"Error reading RSS data.");


while (
$data fread($fp4096))
   
xml_parse($xml_parser$datafeof($fp))
      or die(
sprintf("XML error: %s at line %d",
         
xml_error_string(xml_get_error_code($xml_parser)),
         
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>

Please smbdy help and tell me easiest way to do that....

Dax IX 04-25-2012 12:33 AM

I'm just curious if registering the navbar is always necessary if you're creating a template for your own vB page, and if so, should the first post be updated to illustrate this?

And where the hell is the documentation on things like this:

Quote:

Originally Posted by Boofo (Post 2287132)
Try this in the parse_templates hook:

Code:

require_once(DIR . '/includes/class_template_parser.php');
$parser = new vB_TemplateParser('<div id="toplinks" class="toplinks">');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$find = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$parser = new vB_TemplateParser('<div style="float:right; margin: 5px -12px 5px 10px;">{vb:raw mycode}</div>');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$replace = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$vbulletin->templatecache['header'] = str_replace($find, $find . $replace, $vbulletin->templatecache['header']);
unset($find, $replace);


Or do you have to go through all the various files yourself to learn all of the functions and hope you stumble on what you're looking for?

Boofo 04-25-2012 02:14 PM

You won't stumble on to that anywhere in the files. ;)

Easy5s.net 04-28-2012 08:26 AM

Pls help me :(
https://vborg.vbsupport.ru/showthread.php?t=282142

Seductor 05-14-2012 10:52 PM

If I have this:
PHP Code:

$my_array = array(1,2); 

How can I render my template in order to show it? I don't know which key it is being used. If I do this:
Code:

{vb:raw my_array}
It is rendered like:
Code:

Array
PS: By the way, do you know any tutorial about how to send queries to the database from vBulletin?

BirdOPrey5 05-15-2012 12:41 AM

{vb:raw my_array.0} = 1
{vb:raw my_array.1} = 2

cellarius 05-15-2012 05:11 AM

Quote:

Originally Posted by Seductor (Post 2329431)
If I have this:
PHP Code:

$my_array = array(1,2); 

How can I render my template in order to show it? I don't know which key it is being used. If I do this:
Code:

{vb:raw my_array}
It is rendered like:
Code:

Array

See the article:
PHP Code:

{vb:raw my_var}
{
vb:raw my_array.key1

Quote:

PS: By the way, do you know any tutorial about how to send queries to the database from vBulletin?
https://vborg.vbsupport.ru/showthread.php?t=119350

Seductor 05-15-2012 09:36 AM

Oh, and is there any way to show all my array cells If I don't know which size is the array?

Edited: I suspect that it is done in this way.
Code:

<vb:each from="my_array" key="key1" value="my_result">
    {vb:var my_result}
</vb:each>

I am doing something wrong. I have this:
resource(46) of type (mysql result)

And each row is:
Code:

array(21) { ["id"]=> string(2) "18" ["name"]=> string(5) "ABRIR" ["description"]=> string(23) "Iniciar la interacci?n." ["userid"]=> string(4) "2858" ["username"]=> string(20) "Seducci?n Cient?fica" ["dateline"]=> string(10) "1311875182" ["lastupdate"]=> string(10) "1311933838" ["categoryid"]=> string(1) "1" ["status"]=> string(1) "1" ["ipaddress"]=> string(13) "81.202.205.41" ["attach"]=> string(1) "0" ["threadid"]=> string(1) "0" ["lastupdater"]=> string(20) "Seducci?n Cient?fica" ["lastupdaterid"]=> string(4) "2858" ["tags"]=> string(16) "abrir,escalada 1" ["popup"]=> string(23) "Iniciar la interacci?n." ["views"]=> string(1) "0" ["votenum"]=> string(1) "0" ["votetotal"]=> string(1) "0" ["linkurl"]=> string(7) "http://" ["banner"]=> string(7) "http://" }
I'm doing this in my template:
Code:

<vb:each from="my_query" value="sentence">
  Test {vb:raw sentence.name}
</vb:each>

Notice this: Test {vb:raw sentence.name}

But It doesn't show nothing, as if the each is not being executed. I expected to show, at least, 46 Test words.

kh99 05-15-2012 12:52 PM

Quote:

Originally Posted by Seductor (Post 2329515)
I am doing something wrong. I have this:
resource(46) of type (mysql result)


You are registering the return from one of the query functions. You need to call fetch_array() to get an array for each row, like:

Code:

$results = $db->query_read("some sql");
while ($row = $db->fetch_array($results))
{
    // do something with $row
}


Of course each row is an array (even if you only selected one column). If you are selecting one column from a number of matching rows, you won't get an array with all the matching values, you still get an array for each row. If you want an array with all the matching values you'd have to build that yourself.

Note also that you don't *have* to register an array to your template and use vb:each - you could format your own html string in the while loop above, then just register the string.

tbworld 05-26-2012 07:20 PM

[QUOTE=Boofo;2287132]Try this in the parse_templates hook:

Boofo, I was working on specialized routine and trying to use some of the vb-ojects to solve my problem when I came across the code you posted here. This redirected me to the right vb routines. Thanks so much for sharing!

Dave-ahfb 05-26-2012 08:11 PM

I have a problem on a page. I can use the variable {vb:raw companyname} in the places of the template that I need to. However when I want to place it in my navbits which are created by the php file it just echos itself.
Code:

$navbits = construct_navbits(array('' => '&nbsp;</span></li><li class="navbit"><span><a href="/">Home</a></span></li><li class="navbit"><span><a href="../hostindex.php">Web Hosting</a></span></li><li class="navbit lastnavbit"><span>{vb:raw companyname}
 
'));
$navbar = render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = '$companyname';
$templater = vB_Template::create('headerincludea');
$headerincludea = $templater->render();

$templater = vB_Template::create('webhost-php');
$templater->register('companyname', $companyname);
$templater->render();
 

 
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
$templater->register('headerincludea', $headerincludea);


print_output($templater->render());


kh99 05-26-2012 08:43 PM

Try putting $companyname in your navbits instead of {vb:raw companyname} Since it's in a single-quoted string you need to use concatenation, like:

Code:

$navbits = construct_navbits(array('' => '&nbsp;</span></li><li class="navbit"><span>
<a href="/">Home</a></span></li><li class="navbit"><span>
<a href="../hostindex.php">Web Hosting</a></span></li>
<li class="navbit lastnavbit"><span>' . $companyname . '
 
'));


Dave-ahfb 05-26-2012 08:57 PM

Quote:

Originally Posted by kh99 (Post 2333261)
Try putting $companyname in your navbits instead of {vb:raw companyname} Since it's in a single-quoted string you need to use concatenation, like:

Code:

$navbits = construct_navbits(array('' => '&nbsp;</span></li><li class="navbit"><span>
<a href="/">Home</a></span></li><li class="navbit"><span>
<a href="../hostindex.php">Web Hosting</a></span></li>
<li class="navbit lastnavbit"><span>' . $companyname . '
 
'));


Thanks a ton! I had tried $companyname without the '. .' and had the same results (echoed $companyname.

Chr1sj 05-31-2012 11:57 AM

Can anyone help me out what i'm doing wrong?

i'm trying to add something to the Default navbar template. (a server status for my game server)
but first i'm trying out the example but i can't get it to work.

This is my plugin setup.
Product : vBulletin
Hook location: Global_start
Title: server Status
execution order :5

Plugin code:
Code:

/* Some Code, setting variables, (multidimensional) array */
$my_var = "abc";

/* render template and register variables */
$templater = vB_Template::create('navbar');
    $templater->register('my_var', $my_var);
$templater->render();

Then in the navbar template of my default style i add
Code:

{vb:raw my_var}
even tried withing
Code:

<p>{vb:raw my_var}</p>
Anyone able to help me out ?

Edit: and Enable Plugin/Hook System is enabled also

kh99 05-31-2012 12:02 PM

You don't want to render the navbar template because the vbulletin code already does that for you. To get your variable registered to that template you want to use preRegister, like;

Code:

$my_var = "abc";
vB_Template::preRegister('navbar', array('my_var' => $my_var));


Chr1sj 05-31-2012 12:28 PM

Thanks a lot. :up:
Now i can start creating my plugin understanding the preRegister.

codewaggle 06-10-2012 08:41 AM

Quote:

Originally Posted by Abe Babe (Post 1953310)
I have a template that I need to insert into multiple pre-existing templates. After a bit of struggling, I have managed to get the following code running.

Code:

$templater = vB_Template::create('layout_start');
    $templater->register('my_var', $my_var);
$templatevalues['start_insertvar'] = $templater->render();
vB_Template::preRegister('FORUMHOME', $templatevalues);

I have two questions. Is there any way to preRegister for more than one pre-existing template (or a global registration), or do I have to create Plugins for every page I want to add this to (*groan*)? And what is the best hook to have this on. I am currently using 'parse_templates'.

------------------------------------

I'm doing this using $GLOBALS[templatevalues] = $templatevalues; rather than preRegister().

Code:

$templater = vB_Template::create('layout_start');
$templater->register('my_var', $my_var);
$templatevalues['start_insertvar'] = $templater->render();

$GLOBALS[templatevalues] = $templatevalues;

UPDATE: (Thanks to kh99 for his guidance.)
The following line isn't needed and was used incorrectly:
$template->register_global('templatevalues');


Then use this in the templates where you want the output to appear:
Code:

{vb:raw GLOBALS.templatevalues.start_insertvar}
Be Well


All times are GMT. The time now is 12:05 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.02401 seconds
  • Memory Usage 2,002KB
  • 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
  • (25)bbcode_code_printable
  • (1)bbcode_html_printable
  • (14)bbcode_php_printable
  • (14)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