View Full Version : process_template_conditionals doesn't work
harmor19
06-01-2007, 04:54 PM
I am planning on using the function 'process_template_conditionals()' in a script I'm making for vBulletin. It's returning "Test" even though the conditional should return false.
require_once(DIR . '/includes/adminfunctions_template.php');
$custom = "<if condition='1 == 0'>Test</if>";
$results = process_template_conditionals($custom);
echo $results;
Adrian Schneider
06-01-2007, 05:20 PM
Use single outer quotes instead of double... (so the condition is enclosed in double quotes). I haven't looked at the function, but I'm pretty sure that's how they are parsed.
require_once(DIR . '/includes/adminfunctions_template.php');
$custom = '<if condition="1 == 0">Test</if>';
$results = process_template_conditionals($custom);
var_dump($results);
harmor19
06-01-2007, 05:28 PM
It doesn't make a difference.
This Works
require_once(DIR . '/includes/adminfunctions_template.php');
$tt = $db->query_first("SELECT * FROM ah_media WHERE mediaid = '1' ");
$done = compile_template($getfield['fieldXX']);
eval('$show = "' . $done . '" ;');
echo $show;
I tested it out and added die(); in the column and it parses it as text :)
I'm not that good when it comes to writing tutorials but can you understand it OK?
================================================== ==============
This tutorial will show you how to return data from a column you've created and parse template conditionals.
<?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
echo $done;
?>
I have tested the security and it returns dangerous code as plain text. This means that no one can do mischievous actions towards your forums.
================================================== ==============
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.