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.


All times are GMT. The time now is 08:37 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01504 seconds
  • Memory Usage 1,755KB
  • 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
  • (1)bbcode_code_printable
  • (7)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