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)

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.


All times are GMT. The time now is 10:56 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.03206 seconds
  • Memory Usage 1,796KB
  • 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
  • (8)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (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