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)

BirdOPrey5 07-06-2011 12:45 AM

Quote:

Originally Posted by Boofo (Post 2217258)
Well, yes and no. Since I did it in the forumhome_start hook, it needed those pre-registered for my new template. As long as the variables are good at that hook, then it will work the way I did it.

The forumhome doesn't care about the old template as long as I pre-register everything for my new template. Doing it in the parse_templates hook might be why it didn't work for you with your code. You would have to check whether whatever variables you are pre-registering have already been validated at whatever hook you are using.

Now I'm getting confused. And it hurts! LOL

Don't be confused- the important thing is it works and all is well. :up:

EquinoxWorld 07-08-2011 03:38 PM

Hello everyone, I have been reading this article over and over again trying to figure out what I am doing wrong. Basically I am trying to put the contents of one template into another using a plug in. The template in question are:

-OFTW
-COFTW_FAQ

I want to be able to put the contents of template COFTW_FAQ into a variable that I can then use in OFTW template. I am using a script (oftw.php) which uses the OFTW template; I need to be able to insert the contents of COFTW_FAQ into that template using a plug-in. So this is what I have so far:

Plug-in 1: Hook: Global Start

PHP Code:

$templater vB_Template::create('COFTW_FAQ'); 
    
$templater->register('oftw_faq'$oftw_faq); 
$mytemplate_rendered $templater->render(); 

Plug-in 2: Hook: Global Start

PHP Code:

$templater vB_Template::create('OFTW'); 
    
$templater->register('COFTW_FAQ'$mytemplate_rendered); 
$mytemplate2_rendered $templater->render(); 

And I am using the following variable to call the contents of COFTW_FAQ into OFTW template:

Code:

{vb:raw COFTW_FAQ}
With no avail; I get a blank where the content of the variable should be. Any ideas what I am doing wrong anyone??

Please Help I have been hitting myself in the head for the last 4 hours! :(

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

UPDATE!!!

After more thinking... I can see that I was a bit off, I am now using only plug in to try and accomplish what I want but still just blank...

Hook Location: Process Templates Complete
PHP Code:

$templater vB_Template::create('OFTW_FAQ');
$oftw_faq $templater->render();
vB_Template::preRegister('OFTW',array('oftw_faq ' => $oftw_faq)); 

Using: {vb:raw oftw_faq} in the OFTW template but still nothing... Am I getting closer??? :(

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

GOT IT!!! FINALLLLY!!!!! xD

I had to just register my variable in the actual oftw.php file . Since it was a custom page the script did not have the variable registered so I added
PHP Code:

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

to the oftw.php file and added the last plug-in above and voila! Perfect!! This opens up a whole new world for me. :) Anywho, just thought i'd share my conquering :)

cellarius 07-11-2011 04:34 AM

Congrats - good to see you got it working :D

BirdOPrey5 07-11-2011 11:19 AM

Quote:

Originally Posted by EquinoxWorld (Post 2218222)
Hello everyone, I have been reading this article over and over again trying to figure out what I am doing wrong. Basically I am trying to put the contents of one template into another using a plug in. The template in question are:

-OFTW
-COFTW_FAQ

I want to be able to put the contents of template COFTW_FAQ into a variable that I can then use in OFTW template. I am using a script (oftw.php) which uses the OFTW template; I need to be able to insert the contents of COFTW_FAQ into that template using a plug-in. So this is what I have so far:

Plug-in 1: Hook: Global Start
...

As has been mentioned here before global_start is a bad hook to use in VB4. It was included for compatibility with older mods and is expected to be removed at some point- you can't count on it existing in non-forum parts of the site.

global_bootstrap_init_start should be used instead of global_start in most circumstances.

EquinoxWorld 07-11-2011 06:17 PM

Quote:

Originally Posted by BirdOPrey5 (Post 2219273)
As has been mentioned here before global_start is a bad hook to use in VB4. It was included for compatibility with older mods and is expected to be removed at some point- you can't count on it existing in non-forum parts of the site.

global_bootstrap_init_start should be used instead of global_start in most circumstances.

For rendering template and such which is the most recommended then? I'm assuming "process_template_complete" ? Or does it depend on each case?

Adrian Schneider 07-11-2011 06:23 PM

If you are going to assign several variables in a row, you may want to use the quickRegister function, as it is a lot more readable and clear what is happening (IMO).

PHP Code:

$page vB_Template::create('xxx_newpost');
$page->quickRegister(array(
    
'newpost'        => $newpost,
    
'messagearea'    => $messagearea,
    
'editorid'       => $editorid,
    
'prefix_options' => fetch_prefix_html($foruminfo['forumid'], $newpost['prefixid'], true),
    
'tagcloud'       => prepare_tagcloudlinks(prepare_tagcloud('usage')),
    
'faqs'           => xxx_fetch_faqs('vb3_board_usage'),
    
'topics'         => xxx_fetch_topics(),
    
'strategies'     => xxx_fetch_strategies($parentId),
    
'moderators'     => xxx_fetch_moderators(),    
)); 


BirdOPrey5 07-11-2011 07:32 PM

Quote:

Originally Posted by EquinoxWorld (Post 2219417)
For rendering template and such which is the most recommended then? I'm assuming "process_template_complete" ? Or does it depend on each case?

it depends where the template will be needed, if it will only be on showthread than one of the showthread hooks... but if it might be called anywhere than process_templates_complete or parse_templates seem to work. I don't know if one is better than the other.

cellarius 07-12-2011 03:01 AM

As a general rule: Use a hook that is only called where you need the variable. Normally, you execute code before registering to get the values, and you want to run that only if it's needed. Of course, using stuff like if THIS_SCRIPT will do the job, too.

Murtific 07-20-2011 12:44 AM

i learned how to make custom templates like this. I have a variable that i want to be able to use on the header on every page in vbulletin. I cant get it to save my variable globaly tho. I'm only able to use this var within the template. I read the part where it talked about Save into an array and preregister to use in an existing/stock template. but could not get it to work. by the way, I have no idea how to show code on here

Code:

$eventlist = mysql_query("SELECT * FROM thread WHERE forumid = 8 ORDER BY dateline DESC", $connection);
if (!$eventlist) {
die("Database selection failedquery:SEEPASSWORD: " . mysql_error());
}
while ($row = mysql_fetch_array($eventlist)) {
$zthreadid .= $row["threadid"];
$zdateline .= $row["dateline"]."<br />";
$zlink .= "<a href='showthread.php?{$row["threadid"]}'>" . $row["title"]."</a>" . "<br />";
}

$templater = vB_Template::create('threads');
$templater->register('zthreadid', $zthreadid);
$templater->register('zlink', $zlink);
$templater->register('zdateline', $zdateline);
$zlink2['$zlink'] = $templater->render();
vB_Template::preRegister('header',array('zlink2' => $zlink2));

In the stock header template I put {vb:raw zlink2} but its not showing up. Although in the template I created it displays fine due to the fact that I copied the entire header template and stuck it in my template instead of calling {vb:raw header} in my custom template. Any ideas???

HMBeaty 07-20-2011 12:49 AM

Quote:

Originally Posted by Murtific (Post 2222691)
by the way, I have no idea how to show code on here

Just paste your code you're using inside code/html/php tags. For example:

[code.]your code here[./code]
Would be
Code:

your code here
[php.]your code here[./php]
Would be
PHP Code:

your code here 

[html.]your code here[./html]
Would be
HTML Code:

your code here
Obviously without the "." in the tags though :)


All times are GMT. The time now is 02:15 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.02198 seconds
  • Memory Usage 1,773KB
  • 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
  • (1)bbcode_html_printable
  • (6)bbcode_php_printable
  • (5)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