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)

fxdigi-cash 06-13-2013 05:43 AM

how to render avatar to custom page??

any idea?

tommythejoat 07-22-2013 04:53 PM

I am trying to update a field I added to the thread table from a set of plugins that will be called whenever a post is edited or a new thread created. There is nothing to display. If the current post contains an image or an attachment, I want to copy the postid to my new field.

I think I need to preregister the node in the $thread array, but I am not sure how to do that. Can I freely reference an existing array in the preregister method?

Here is the code I have now. The commented line is what I would expect the eventual sql statement to be.
Code:

if (!$thread['thumbpostid']) //there is no thumbpost defined
{
        if ((strpos($post['pagetext'], '[/IMG]')  or ($post['attach']) ) // post has an attachment or there is an [img] tag
        {
                // $vbulletin->db->query_write("UPDATE ".TABLE_PREFIX."thread SET thumbpostid = ".$postid." WHERE threadid = ".$threadid);
                $threadman->setr('thumbpostid', $postid);
        }
}


Fraxter 08-10-2013 10:29 AM

I'm currently working on an old vb addon to make it compatible to vb4.

Maybe somebody can help me with this following line:

PHP Code:

eval('$output["variable"]="'.fetch_template('new_template').'";'); 

My first try was like that:

PHP Code:

eval('$output["variable"]="'.vB_Template::create('new_template')->render().'";'); 

But i think that's not enough, the eval produces errors.

Thanks in advance. :)

kh99 08-10-2013 10:51 AM

I think you just need something like this:
PHP Code:

$output["variable"] = vB_Template::create('new_template')->render(); 


since the eval has been moved in to the vB_Template class. But if the template requires any variables, they now have to be registered. So it's likely you need something like:

PHP Code:

$templater vB_Template::create('new_template');  
$templater->register('var1'$var1);
$templater->register('var2'$var2);
// etc, for each var needed by the template

$output["variable"] = $templater->render(); 


Fraxter 08-10-2013 10:59 AM

Thanks for your help.
That was exactly what i was looking for. :)

kh99 08-10-2013 11:48 AM

I should probably mention just in case, you don't have to register *every* variable because some standard vb ones are automatically registered, like bbuserinfo, style, show, vboptions, etc.

Kestryll 03-31-2014 05:09 PM

I have to admit, this is going a bit beyond my scope of knowledge and I'm a bit lost.

I'm trying to place the same rotating banner ads in 4.2.2 that I currently use in 3.8.7
I've been told I need to register the templates and have been directed to this thread.
I am certain the answer is here however I'm not grasping it.

I currently run in house advertising via a table in the header that calls to plugins using the PHP random feature like this:
In Table in header:
Quote:

<td style="width: 120px; text-align: center; height: 60px;">$random_banner12[$random_number12]</td>
In plug ins with a hook location of 'parse_templates' Execution order 5
Quote:

$random_number12 = rand(1, 3);

$random_banner12[1] = '<a href="http://www.vendor/" target="_blank"><img src="/images/ads12/vendor.gif" alt="" border="0" /></a>';
I'm not sure which of these needs to be registered or where to do that at.
Any help would be appreciated.

Lynne 03-31-2014 05:27 PM

At the end of that plugin, you need to register that variable for use in the header template.

PHP Code:

vB_Template::preRegister('header', array('random_banner12' => $random_banner12)); 


Kestryll 03-31-2014 09:08 PM

Just so I have this right before trying it and turning my vB install in to Pong game, in the Plug In PHP Code box I add that to the end like this:
PHP Code:

$random_number11 rand(13);

$random_banner11[1] = '<a href="http://www.1022fungun.com/" target="_blank"><img src="/images/ads11/1022_120x60.gif" alt="" border="0" /></a>';
$random_banner11[2] = '<a href="http://www.addaxtactical.com/" target="_blank"><img src="/images/ads11/Addax120x60.gif" alt="" border="0" /></a>';
$random_banner11[3] = '<a href="http://www.turners.com/" target="_blank"><img src="/images/ads11/turners120x60.gif" alt="" border="0" /></a>';
vB_Template::preRegister('header', array('random_banner11' => $random_banner11)); 

Then I place this in the Header:
PHP Code:

$random_banner11[$random_number11


Lynne 04-01-2014 04:15 PM

Did you try it? You really should have a test site set up so you can try this stuff before doing it on a live site.

Kestryll 04-01-2014 05:22 PM

I do have a test site up with a separate database and vB install on it for testing prior to trying anything on my live forum.

You'll have to excuse my manner of asking follow up questions, when I can't get something to work I tend to ask questions in the form of clarification of what I am doing assuming I have made an error rather than saying 'that didn't work'. It seems more respectful of those trying to help.
The comment about roasting my vB install is mostly comedy however I did manage to do something to my test install when I first tried to make the ad banners work that killed it and required a wipe and reinstall.

So far I have not been able to get the random banners to display, all I have gotten is the header code displaying above the title.
I have placed the header code in various places within the header template and have placed the registration code at the very end of the plug in as above and tried it as the second line of the plug in.
All with the same results, I can only assume that I am missing a step somewhere.

Lynne 04-01-2014 10:17 PM

I couldn't tell from your post whether you were asking for help or not. But, I did just notice that you have the variable entered wrong in your template (that's what happens when you look at vB3 and vB4 and vB5 sites all the time!). It's

{vb:raw random_banner11['$random_number11']}

And, I didn't notice you had two variables - you need to register each of them.

Lynne 05-16-2014 05:06 PM

The first post shows you how to register a variable here:
PHP Code:

$my_insertvar $templater->render();
vB_Template::preRegister('FORUMHOME',array('my_insertvar ' => $my_insertvar)); 

That registers the variable $my_insertvar to be used in the template FORUMHOME. Go back and relook at the article and you will see this explained.

Lynne 05-18-2014 04:24 PM

Quote:

Originally Posted by semprot (Post 2498284)
so i need to type that code on all PHP files on root? (usercp.php, forum.php, etc ?)

No, you can add it to a plugin. If you are using it on every page, then you'll want to use a hook location that is on every page - maybe one of the global_* ones. You'll have to try it and see which works best.

npadbidri 11-29-2014 12:59 PM

Hi,

I understand above all things. I just wanted to know that,
{vb:raw user.username}
above code I found in template 'header'.
From where this header template gets object 'user' and how it can able to access it property.

I am interested know where this vBulletin variable like 'user' stored and in which php file?

Can any one help me to understand this?

Thanks!!!!

Lynne 11-29-2014 05:12 PM

Quote:

Originally Posted by npadbidri (Post 2524746)
Hi,

I understand above all things. I just wanted to know that,
{vb:raw user.username}
above code I found in template 'header'.
From where this header template gets object 'user' and how it can able to access it property.

I am interested know where this vBulletin variable like 'user' stored and in which php file?

Can any one help me to understand this?

Thanks!!!!

The header template is rendered in the /includes/class_bootstrap.php file around line 509. So, try looking at the code above there. (But, I don't see any $user variable registered for use in that template, nor do I see the template code "{vb:raw user.username}" being used in the header template. If you do see that, then this may be from a modification.)

TheAdminMarket 02-01-2015 09:08 AM

Any suggestion why the code below does not works as expected?
PHP Code:

<plugin active="1" executionorder="20">
    <
title>Build Advertisments Block</title>
    <
hookname>cache_templates</hookname>
    <
phpcode><![CDATA[
        global 
$db$vbulletin;
        
$group $vbulletin->db->query_first("SELECT * FROM ".TABLE_PREFIX."banners_groups WHERE active=1 ORDER BY lastshow ASC LIMIT 1");
        
$groupid $group["id"];
        
$spots $group["spots"];
        
$random $group["random"];
        
$cellwidth 100/$spots;
        
// Update Group with Last Show Time
        
$timenow time();
        
$vbulletin->db->query_write("UPDATE ".TABLE_PREFIX."banners_groups SET lastshow=$timenow WHERE id=$groupid ORDER BY id ASC");
        
// List Group Advertisments
        
if ($random == 1)
        {
            
$advertisments $vbulletin->db->query_read("SELECT * FROM ".TABLE_PREFIX."banners_advertisers WHERE groupid=$groupid AND active=1 ORDER BY rand() LIMIT $spots");
        } else {
            
$advertisments $vbulletin->db->query_read("SELECT * FROM ".TABLE_PREFIX."banners_advertisers WHERE groupid=$groupid AND active=1 ORDER BY displayorder ASC LIMIT $spots");
        }
        
$main_bit '';
        while (
$advertisment $vbulletin->db->fetch_array($advertisments)) {
            
// Prepare Templates
            
$templater vB_Template::create('banners_main_bit');
            
$templater->register('htmlcode'htmlspecialchars_uni($advertisment[htmlcode]));
            
$templater->register('cellwidth'$cellwidth);
            
$main_bit .= $templater->render();
        }
        
$templater vB_Template::create('banners_main');
        
$templater->register('main_bit'$main_bit);
        
$templatevalues['mybanners'] = $templater->render();
        
vB_Template::preRegister('header'$templatevalues);
    ]]></
phpcode>
</
plugin

Taking in account that:
  1. I used many different hooks like: global_start, global_complete, fetch_templates etc.
  2. I also used many different templates like: ad_global_header1 etc
  3. The same code with only difference the last 2 lines is working in php file if I use: print_output($templater->render());
Thank you very much

EDIT: What I was adding in the templates is: {vb:raw mybanners}

kh99 02-01-2015 11:53 AM

I would use hook parse_templates. You say you've tried "many different templates", do you mean other hean 'header'? Of course you know, but double check that you put {vb:raw mybanners} in the same template that you preRegister() to.

TheAdminMarket 02-01-2015 01:35 PM

Quote:

Originally Posted by kh99 (Post 2535510)
I would use hook parse_templates. You say you've tried "many different templates", do you mean other hean 'header'? Of course you know, but double check that you put {vb:raw mybanners} in the same template that you preRegister() to.

hmm... Didn't tried that hook and sounds matching the case. As for the rest. Except a typo that I had at the very begining (ad_global_header_1 instead ad_global_header1), the other were correct. And yes I tried many templates, even custom ones from my addons. So:
  1. Difficult to be the template name or the content as the variable is correct.
  2. PHP code is correct as it works with a test file that I did.
After all the hook must be wrong. Let's try with yours :)

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

Quote:

Originally Posted by kh99 (Post 2535510)
I would use hook parse_templates.

That did the trick. Thank you.

Easy5s.net 02-20-2015 03:13 PM

hock process_templates_complete

PHP Code:

$templater vB_Template::create('testtest');
    
$templater->register('var1'$var1);
    
$templater->register('var2'$var2);
$out[test] = $templater->render();
$ad_location['global_below_navbar'] .= $out

but not work???. I want auto add temp to below navbar.

Master Of Unive 04-06-2015 12:09 AM

I think using member_build_blocks_start is much better than member_complete as it allows you to access function preRegister of vB_Template class.

Gizmo99 05-15-2015 06:36 AM

JUst a quick question

Playing with 4.2.2

Tried using the $templater but no dice but (Sorted)

BUT !!!! eval does work ? is this right ?



PHP Code:

if ($_POST['do']  == 'start')
{
            eval(
'print_output("'fetch_template('online_menu') . '");');

// Template show
$templater vB_Template::create('online_menu');
$templater->register_page_templates();
print_output($templater->render());




Black Snow 05-15-2015 06:42 AM

Quote:

Originally Posted by Easy5s.net (Post 2538101)
hock process_templates_complete

PHP Code:

$templater vB_Template::create('testtest');
    
$templater->register('var1'$var1);
    
$templater->register('var2'$var2);
$out[test] = $templater->render();
$ad_location['global_below_navbar'] .= $out

but not work???. I want auto add temp to below navbar.

Try this:

Code:

$templater = vB_Template::create('testtest');
$templater->register('var1', $var1);
$template_hook[global_below_navbar] .= $templater->render();


taravasya 10-01-2015 08:23 AM

Help me please! What I`m do wrong?...
I trying show some info on showthread page.
-----------------------------------------------------------------
PHP Code:

<plugin active="1" executionorder="5">
    <
title>RightSideBlock</title>
    <
hookname>showthread_start</hookname>
    <
phpcode><![CDATA[
$mynewvar "MyNewVar";
$templater vB_Template::create('rightside_on_showthread');
    
$templater->register('mynewvar'$mynewvar);
$rightside_rendered $templater->render();
    ]]></
phpcode>
</
plugin

------------------------------------------------------------------
HTML Code:

<template name="rightside_on_showthread" templatetype="template" date="1337106668" username="taravasya" version="1.0.0"><![CDATA[
<div class="rightsideinfo">
{vb:raw mynewvar}</div>
]]></template>

------------------------------------------------------------------
And so on SHOWTHREAD template I adding:
HTML Code:

{vb:raw rightside_on_showthread}
------------------------------------------------------------------
But with no luck (((
In place in what I was want to add my info I have white space(without my div class="rightsideinfo" in inspector of page). But in debug info, I have not cached template rightside_on_showthread.

UPDATE -------------------------------------

I was thinking if I take vars into my own template, then I don`t need to use vB_Template:: preRegister for add my template in showthread. But I was wrong...))

Lynne 10-04-2015 02:46 PM

PHP Code:

$templater vB_Template::create('rightside_on_showthread');
    
$templater->register('mynewvar'$mynewvar);
$rightside_rendered $templater->render();
vB_Template::preRegister('SHOWTHREAD', array('rightside_rendered' => $rightside_rendered)); 


taravasya 10-15-2015 03:15 PM

Thanks, Lynne! Actually I wrote in a previous message, that I understood my mistake, but your variant helped me to make my code more succinctly! Thanks!

taravasya 10-29-2015 09:54 PM

Another problem(((
In hook showthread_similarthreadbit I add next code:
PHP Code:

        $templater vB_Template::create('rightside_similarthreadbit'); 
        
$templater->register('simthread'$simthread); 
        
$templatevalues .= $templater->render(); 
        
vB_Template::preRegister('SHOWTHREAD', array('templatevalues' => $templatevalues)); 

Like this I have just ONE LAST result from query. What I have to do for have all results?
This hook added in showthread.php on 1978.
I was thinking, if this hook placed in a while cycle, I will have all results from this cycle. But no.... :(

irantk 12-12-2018 06:42 AM

Hi
my plugin load in "showthread_complete" and it's code is:
PHP Code:

global $pagenumber$perpage$totalposts$pagetitle$threadinfo;

$totalpages ceil($totalposts $perpage);
$templater vB_Template::create('opengraph_inshowthread');
$templater->register('pagenumber'$pagenumber);
$templater->register('totalposts'$totalposts);
$templater->register('perpage'$perpage);
$templater->register('totalpages'$totalpages);
$templater->register('pagetitle'$pagetitle);
$templater->register('pagedescription'$threadinfo['description']);
$template_hook['headinclude_bottom_css'] .= $templater->render(); 

and "opengraph_inshowthread" template code is:
Code:

<meta property="og:title" content="{vb:raw pagetitle} - page {vb:raw pagenumber} of {vb:raw totalpages} pages" />
But nothing adds to head. how to add my template to head?
I need to point out that I can not load the plugin in the "parse_template". Because the page number and other variable is not recognized in "parse_template".
and why "{vb:rawphrase thread.title}" not work in my template?


All times are GMT. The time now is 12:01 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.03114 seconds
  • Memory Usage 1,895KB
  • 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
  • (2)bbcode_html_printable
  • (16)bbcode_php_printable
  • (7)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (28)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