Back to vBulletin 3 Articles

[How-To] Use Template Conditional in any Script
by harmor19 02 Jun 2007

This tutorial will show you how to return data from a column you've created and parse template conditionals.

PHP Code:
<?php

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

// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT''my_script'); 

// #################### 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();

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

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');

//You must include this in order to parse HTML based conditionals 
require_once(DIR '/includes/adminfunctions_template.php');
// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################

//First we need to query the table.
$sql $db->query_first("SELECT * FROM " TABLE_PREFIX "my_table WHERE column = 'X' ");

//Now we need to convert the HTML based conditionals to PHP based 
eval('$done = "' compile_template($sql['my_field']) . '" ;');

//Print the results to the screen
eval('print_output("' fetch_template('my template') . '");');

?>


For sake of this article let's say "$sql['my_field']" contains the following
HTML Code:
<if condition="is_member_of($bbuseruserinfo, 12)">
To access the arcade click on "Links" to access the menu.<br />
Within the menu choose "Arcade".
<else />
<if condition="!is_member_of($bbuseruserinfo, 12)">
To access the arcade you need a minimum of 1000 posts. Currently you only have $bbuserinfo[posts]
</if>
</if>


You'll need to take the variable "$done" and place it in "my_template".
HTML Code:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
$headinclude
<title>$vboptions[bbtitle]</title>
</head>
<body>
$header
$navbar
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" 
align="center">
<tr>
<td class="tcat">My Custom Page Title</td>
</tr>
<tr>
<td class="alt1">$done</td>
</tr>
</table>
$footer
</body>
</html>

View the attachment to see what the end result.

I have tested the security and it returns dangerous code as plain text. This means that no one can perform mischievous actions towards your forums.
Attached Thumbnails
Click image for larger version
Name:	advfaq_faq.png
Views:	223
Size:	5.3 KB
ID:	65106  

vblts.ru supports vBulletin®, 2022-2024