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)

Murtific 07-20-2011 02:53 AM

Quote:

Originally Posted by HMBeaty (Post 2222694)
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 :)

Thanks, got it. Now back to my previous post, anybody have any ideas?

BirdOPrey5 07-20-2011 11:34 AM

What hook is your code on?

Murtific 07-20-2011 02:32 PM

what's a hook? I dont have a hook. I ended up just doing this. I basically just added my database code to the forum.php file and got it to work, but i have to modify every template like I mentioned in this thread, i'd rather use this thread https://vborg.vbsupport.ru/showthread.php?t=267120

kh99 07-20-2011 03:20 PM

Quote:

Originally Posted by Murtific (Post 2222873)
what's a hook? I dont have a hook. I ended up just doing this. I basically just added my database code to the forum.php file and got it to work,

[S]That's probably the issue - if you put it in after global.php, it's too late to affect the header[/S]. (Edit: actually that's wrong, I think you have until another template is rendered, so what you did could have worked, but try it with a plugin anyway.)

See my post in the other thread.

Dave-ahfb 07-23-2011 04:36 PM

First let me say that I am not PHP literate, but can find my way around 9 times out of 10.

I am creating custom templates to include my non vb scripts but am having troubles when trying to include a variable(?) from this script in any template outside the main body.

I will try to be as detailed as possible, hopefully any responses will include the information I give as a real life example so that I can get an understanding of what was done.


Goal: to take $companyname from the below script and add it to my page title, navbits etc. (currently I only get echos of $companyname or {vb:raw companyname}, depending on where I am in my efforts.
PHP Code:

if (isset($_GET['company']))
    
$company $_GET['company'];
   else
    
$company '100megs';
$result mysql_query("select * from hostwebhost where companyname = '$company'");
if (!
$result) {
$numrows 0;
} else {
$numrows mysql_num_rows($result);
}
for(
$x=0;$x<$numrows;$x++){
while (
$row mysql_fetch_array($result)){
$host_id $row[0];
$companyname $row[1];
$emailaddress $row[2]; 
$URL $row[3]; 
$track $row[4]; 
$imgtop $row[5]; 
$imgright $row[6]; 
$imgbody $row[7]; 
$joined $row[8]; 
$password $row[9]; 
$isvalid $row[10]; 
$supportlist $row[11]; 
$street1 $row[12]; 
$street2 $row[13]; 
$city $row[14]; 
$state $row[15]; 
$zip $row[16]; 
$country $row[17]; 
$contactname $row[18]; 
$contactphone $row[19]; 
$contactfax $row[20]; 
$suggested $row[21]; 
$comdescrip $row[22]; 
$registered $row[23]; 

plugin info:
PHP Code:

locationglobal_bootstrap_init_start
title
Webhost-php Include
execution order5
code
:
ob_start();
ob_start();
include(
'/srv/www/findnewhosting.com/public_html/webhost1.php');
$webhost ob_get_contents();
ob_end_clean(); 
vB_Template::preRegister('webhost-php', array('webhost' => $webhost)); 

As you can see the script is webhost1.phpwhich includes the first set of code above. Please note that the custom page is webhost.php which contains the following:
PHP Code:

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT''webhosting');
define('CSRF_PROTECTION'true);  
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('webhost-php',);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
chdir ('/srv/www/findnewhosting.com/public_html');

require_once(
'/srv/www/findnewhosting.com/public_html/global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$navbits construct_navbits(array('' => '&nbsp;</span></li><li class="navbit"><span><a href="/">Home</a></span></li><li class="navbit"><span><a href="../hostindex.php">Web Hosting</a></span></li><li class="navbit lastnavbit"><span>{vb:raw companyname} 

'
));
$navbar render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle '$companyname';
$templater vB_Template::create('headerincludea');
$headerincludea $templater->render();
$templater vB_Template::create('webhost-php');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('pagetitle'$pagetitle);
$templater->register('sidebarext'$sidebarext);
$templater->register('sidebaropen'$sidebaropen);
$templater->register('headerincludea'$headerincludea);


print_output($templater->render());
?>

webhost-php(template):
PHP Code:

{vb:stylevar htmldoctype}
<
html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<
head>
<
title>{vb:raw companyname}</title>
{
vb:raw headerincludea}
{
vb:raw headinclude_bottom}
</
head>
<
body>
{
vb:raw header}
{
vb:raw navbar}
{
vb:raw sidebaropen}
<
br />
<
div id="pagetitle">
<
h1>&nbsp;&nbsp;{vb:raw pagetitle}</h1><br />
</
div>
<
div class="blockbody">
<
div class="blockrow">
<
div align="center">

{
vb:raw webhost}

</
div>
</
div>
</
div>
    {
vb:raw sidebarext}


    {
vb:raw footer}
  </
body>
</
html

If there is any other info I can give to make it easier to solve just let me know.

Dave

BirdOPrey5 07-23-2011 05:30 PM

I don't know if it's your only problem but you didn't register $companynanme in your webhost1.php file, so it won't show in your template.

Dave-ahfb 07-23-2011 05:48 PM

Could you dumb that down please?

BirdOPrey5 07-24-2011 12:50 PM

Quote:

Originally Posted by Dave-ahfb (Post 2224002)
Could you dumb that down please?

At the end of webhost1.php you have this code:

Code:

$templater = vB_Template::create('webhost-php');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
$templater->register('sidebarext', $sidebarext);
$templater->register('sidebaropen', $sidebaropen);
$templater->register('headerincludea', $headerincludea);


print_output($templater->render());

You need to add this line:

Code:

$templater = vB_Template::create('webhost-php');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
$templater->register('sidebarext', $sidebarext);
$templater->register('sidebaropen', $sidebaropen);
$templater->register('headerincludea', $headerincludea);
$templater->register('companynanme', $companynanme);

print_output($templater->render());

ALL variables you need to use in a template MUST be registered to a template before you use it. If you use any other variables you must register them also.

Dave-ahfb 07-24-2011 02:26 PM

Thank you so much. As soon as I can put this paint brush down I will give it a shot.

Dave

heugabel 07-26-2011 05:19 PM

Code:

        $search_text = '<!-- end logged-in users -->';
        $vbulletin->templatecache['FORUMHOME'] = str_replace($search_text, $search_text . fetch_template('forumhome_xyz'), $vbulletin->templatecache['FORUMHOME']);

how i can rewrite this for vb4?

thank you


All times are GMT. The time now is 01:34 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.04845 seconds
  • Memory Usage 1,800KB
  • 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
  • (4)bbcode_code_printable
  • (1)bbcode_html_printable
  • (5)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