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)

Craigr 07-20-2012 02:07 PM

I am creating a custom mod for my site, at the moment i have done this and only get a white page displayed, but at least the result appears. I am not sure what example to follow so that the rest of the showthread template appears too?

Plugin:
Product: vBulletin
Hook Location: showthread_post_start
Title: galleryimagedisplay
Execution Order: 5
PHP Code:
Code:

$result = $db->query_first("SELECT * FROM dbtech_gallery_images WHERE roll_id = '$threadid'");
$id = $result[imageid];
$title = $result[title];

$templater = vB_Template::create('test');
$templater->register('id', $id);
$templater->register('title', $title);
$templatevalues['my_insertvar'] = $templater->render();
vB_Template::preRegister('SHOWTHREAD', $templatevalues);

This is my template:
Code:

{vb:raw id} {vb:raw title}
Edit: Got the above displaying ok now.

BirdOPrey5 07-20-2012 02:46 PM

off hand it's vb:raw in the templates, not vbraw: and there is no $ either.

Code:

Test Text: {vb:raw id} {vb:raw title}

Steve St.Lauren 08-04-2012 12:06 AM

I'm trying to use several of my user custom fields on a page in profile.php. I've got the template working and the page is displaying ok but I can't get the custom fields to display. I've tried a ton of stuff and just can't get it to work - would GREATLY appreciate any help you could provide. Here's what I'm doing now. This is the plug in code going into profile.php:

if ($_REQUEST['do'] == 'showsubscription')
{
echo 'test';
$customfields = array();
fetch_profilefields(0);
$page_templater = vB_Template::create('showsubscription');
$page_templater->register('customfields', $customfields);
}

in the template itself I'm putting in:

{vb:raw customfields.value11}

where I want to use the field. I've also tried customfields.field11 various permutation of userinfo, userfield, etc. I was able to do this in vb3 no problem but having a tough time getting it to work in vB4.

BirdOPrey5 08-04-2012 08:36 AM

Do you have the working 3.x code?

Steve St.Lauren 08-04-2012 08:59 PM

Yes, in VB3 it was very easy - all I had to do was put $bbuserinfo[field11] on the template. The plugin portion of it was:

// ############################ start show subscription info ##########################
if ($_REQUEST['do'] == 'showsubscription')
{
construct_usercp_nav('showsubscription');

$navbits[''] = 'Subscription Status';
$templatename = 'showsubscription';
$url =& $vbulletin->url;
}

BirdOPrey5 08-05-2012 10:34 AM

I'm sorry, either I don't understand what you are trying to do or are missing something big.

Steve St.Lauren 08-05-2012 06:24 PM

I have a number of custom user fields created and I want for the values of those fields to appear on a profile page. In this case it's a subscription status page that lets the user know when their subscription expires and how many issues they have left remaining on their subscription. In VB3 the profile.php page had $bbuserinfo loaded with those fields and they could be called simply by putting $bbuserinfo[field11] in the template - it would put the value there.

showsubscription was the name of the custom template that I created and it would appear along with all of the profile page navigation around it. I have the showsubscription template appearing in vb4 now but I can't get the values of the custom fields to appear on the page. I'm pretty sure it will involve the {vb raw} function and registering a variable for it to be able to appear in the template but just can't figure it out. profile.php must already be loading the custom user fields somewhere because it's used elsewhere on the page.

PyroChixRock 08-12-2012 10:39 PM

I have this little random banner code I've always used through the plugin system, but I can't seem to get it to work on vb4. Can anyone help?

normally, I call for it below the navbar with this...
Code:

<br>
<div style="text-align: center;">
$randombanner
</div>

and this for example, in the plugin area.
Code:

$path = '/forum/images/adbanners/';
$banners = array(
array( 'src' => 'imagine.jpg',
'href' => 'http://www.talkglass.com/'),
array( 'src' => 'waiting.jpg',
'href' => 'http://www.talkglass.com/),
);


$rnd = rand(0,count($banners)-1); // Pick a random array index.  They start with 0, so you have to -1.
$href = $banners[$rnd]['href'];  // Link HREF
$src = $path.$banners[$rnd]['src']; // Image source
$randombanner = '<a href="'.$href.'"><img border="0" src="'.$src.'" /></a>';

Where should i plug these in now for them to work with the built in ad system. it doesn't work using that.

kh99 08-13-2012 12:13 PM

Quote:

Originally Posted by PyroChixRock (Post 2356515)
Where should i plug these in now for them to work with the built in ad system. it doesn't work using that.


Try using hook parse_templates and at the end of your plugin code add:
Code:

vB_Template::preRegister('navbar', array('randombanner' => $randombanner));

Then in the navbar template, use this:
Code:

<br>
<div style="text-align: center;">
{vb:raw randombanner}
</div>


PyroChixRock 08-13-2012 05:59 PM

Thanks, Kevin. I really appreciate you taking the time to reply.

It seems I have everything right but it's not showing up.

I'm not sure what else to do but this is the last thing I need before I can go live with my upgrades. VB is no help because it's custom code.

I'm not sure what else to tell you that would be helpful? Would you be willing to hop over to my test forum and have a look? If so send me a pm and I'll give you login info.


All times are GMT. The time now is 01:15 AM.

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.04808 seconds
  • Memory Usage 1,746KB
  • 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
  • (7)bbcode_code_printable
  • (1)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