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)

cellarius 07-26-2011 05:30 PM

This has been described around the forum several times; either search or open your own thread, this is not related to the topic of this tutorial.

EquinoxWorld 08-04-2011 03:50 AM

Hello everyone, is there any way to include for example this php:

cotw_func_contest_num.php?do=sotw

As a variable in a plugin, then use it in a template?

I also created this thread but am also posting here to see if anyone had any further ideas we could try. Any info would be very much appreciated. Thanks for your time everyone.

MikeF 08-04-2011 04:14 AM

I've been driven nuts. All I want to do is output $random_number using rand(1,99999) and I'm stuck.. why have they made this insanely difficult?

kh99 08-05-2011 08:12 PM

Quote:

Originally Posted by MikeF (Post 2229100)
I've been driven nuts. All I want to do is output $random_number using rand(1,99999) and I'm stuck.. why have they made this insanely difficult?

It actually does make sense, although I'll admit it's not obvious why. What have you tried? You should be able to do something like in a plugin:

Code:

$random_number = rand(1,99999);
vB_Template::preRegister('template_name',array('random_number' => $random_number));

hook location parse_templates is probably a good choice. Of course you need to change template_name to the actual name of the template you want to use the random number in.

Then in the template put
HTML Code:

{vb:raw random_number}

RobDog888 08-14-2011 11:40 PM

Ok been banging my head on this for quite some time now and completely ready to throw in the towel. I dont know why vB had to make things so damn difficult! It used to be really easy and straight forward to extend vB but not so much now.

I just want to pull in my custom template for adding a value to the postbit userifo part using the template hook "postbit_userinfo_right_after_posts"

The variable $post[field5] is already pulled in as I can do the eval like so to test it in the plugin...

Code:

if ($post['field5'])
{
    $templater = vB_Template::Create('postbit_name');
    $template_hook['postbit_userinfo_right_after_posts'] .= $templater->render();
}

My templates phrases are eval'd and outputted in the hook location but $post[field5'] is blank yet how did it evaluate as true if its empty?
If I hard code the template instead of creating it it works fine but I want it to be properly developed and not hacked.

Thanks

cellarius 08-15-2011 06:59 AM

Because it's filled in your PHP script, but you never registered it for use in your template, and that's why it's empty there.

The tutorial does state (in bold red ;)) that you have to register every variable and array you want to use in your custom template. Try:
Code:

if ($post['field5'])
{     
    $templater = vB_Template::Create('postbit_name');
    $templater->register('post', $post)
    $template_hook['postbit_userinfo_right_after_posts'] .= $templater->render(); 
}

Then you should be able to use {vb:raw post.field5} in your template.

RobDog888 08-16-2011 03:30 AM

Thank You for the reply but I guess I will have to start over at square 1 to get a better understanding of the new vB4 architechure

Ok now I made that change and it work! So even though the variable/array is a standard vB one because I made a custom template I have to register the standard variables too it seems. I thought it was just our custom variables

demo7up 08-17-2011 01:40 PM

Quote:

Originally Posted by moonray (Post 1990021)
FINAL WORKING CODE:

Product: vBulletin
Title: Insert Simple PHP
Execution order: 5
Hook Location: global_start
PHP code:
Code:

ob_start();
include('simple.php');
$simple_php = ob_get_contents();
ob_end_clean();

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

Plugin is active: Yes

Now, go to the NAVBAR template and insert
Code:

{vb:raw insert_simple_php}
just under the code
Code:

{vb:raw ad_location.global_below_navbar}

Im trying to use this code to include a php file in my custom page this is what im using

Code:

ob_start();
include('../www/gearstore/jdmgear.php');
$templatevalues['insert_simple_php'] = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('JDMGEAR', $templatevalues);

In my template i have

Code:

{vb:raw insert_simple_php}
It seems it wants to work but im just getting a gray box as such.

actual page http://nycjdm.com/jdmgear.php any ideas?

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

Quote:

Originally Posted by demo7up@gmail.c (Post 2234527)
Im trying to use this code to include a php file in my custom page this is what im using

Code:

ob_start();
include('../www/gearstore/index.php');
$templatevalues['insert_simple_php'] = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('JDMGEAR', $templatevalues);

In my template i have

Code:

{vb:raw insert_simple_php}
It seems it wants to work but im just getting a gray box as such.

actual page http://nycjdm.com/jdmgear.php any ideas?

i figured it out, it was the action script in the swf.. i changed some paths and it is now working ..

I have everything working now i just need to figure out how to intergrate it's login with vb4 if anyone could point me in the right direction that would be great.

HMBeaty 08-18-2011 11:38 PM

Ok, I'm probably overlooking something, or didn't do something right, or something lol, but this is my first time trying to include a custom template within another custom template on vB 4 (it was SO much easier on vB 3 :()

Anyway, this is where I'm at so far:
Plugin
Hook location: process_templates_complete
PHP Code:

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

Template
I'm calling my sidebar template in my template usml_military_ranks (and many others) by using:
Code:

{vb:raw usml_military_ranks_sidebar}
PHP file
In the PHP file for usml_military_ranks I have:
PHP Code:

    $templater vB_Template::create('usml_military_ranks');
        
$templater->register_page_templates();
        
$templater->register('navbar'$navbar);
        
$templater->register('usml_military_ranks_sidebar'$usml_military_ranks_sidebar);
        
$templater->register('mainpagetitle'$mainpagetitle);
        
$templater->register('imp_vars'$imp_vars);
        
$templater->register('pages'$pages);
    
print_output($templater->render()); 

So what am I missing? lol :confused:

kh99 08-19-2011 12:07 AM

You might try taking this line out of the php file:

PHP Code:

$templater->register('usml_military_ranks_sidebar'$usml_military_ranks_sidebar); 


you don't need this and the PreRegister, and this line might actually be registering an undefined variable.


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

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.01447 seconds
  • Memory Usage 1,765KB
  • 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
  • (11)bbcode_code_printable
  • (1)bbcode_html_printable
  • (3)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (2)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