PDA

View Full Version : Evaluating a conditional from a variable in the template


CyberRanger
11-04-2005, 04:16 PM
I have a variable called $pagetext that contains this information:

<if condition="is_member_of($bbuserinfo, 9)">Member of Group</if>More words ...

I want to have that variable evaluated by a template eval('$html .= "' . fetch_template('pagetext') . '";'); and eventually output by another templateeval('print_output("' . fetch_template('shell') . '");');

When I try to do that, the conditional is simply ignored, ie even if the user is not a member of group 9, the "Member of Group" text still appears.

Any ideas on how to do this?

************************************************** ***

Okay, here's a nasty solution I found. First, let me explain the situation better. I have a custom table in the forums db that holds text to be output on a custom webpage. I process that page through vbulletin to use vb's styles, permissions, etc. In my example above, the variable $pagedata, holds the content for the page. It also contains vb conditionals. If I just evaluate the variable in a template, the template was simply ignoring the conditionals.

So .... here is my ugly solution. When the information for that page is updated in my custom table, I create a template for that page.
$db->query("DELETE FROM `" . TABLE_PREFIX . "template` WHERE `title` LIKE '$pageurl'");
$db->query("INSERT INTO `" . TABLE_PREFIX . "template` (`styleid`,`title`,`template`,`template_un`,`templ atetype`,`dateline`,`username`,`version`) VALUES (1, '".$pageurl."','".mysql_real_escape_string(compile_template($pageda ta))."','".mysql_real_escape_string($pagedata)."','template',".TIMENOW.",'Brent Layman','3.5.0')");


then I rebuild my templates: require_once(DIR . '/includes/adminfunctions.php');
build_all_styles();

Now, when I want to display the page, I first call the template and evaluate the bbcode: eval('$pagedata = "' . fetch_template($pageurl) . '";');

$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$parsed_text = $parser->do_parse($pagedata, 1, 1, 1, 1, 1, $cachable);
$pagedata = $parsed_text; and now evaluate into my original template:
eval('$html .= "' . fetch_template('pagetext') . '";');

There's gotta be a better way!! :o

TyleR
11-04-2005, 07:29 PM
Well, first off, you didnt define what the member is of in the conditional.. it should be this:

<if condition="is_member_of($bbuserinfo[usergroupid], 9)">Member of Group</if>More words ...

as for the other stuff, I dont have a clue..not in tune with vB's 3.5.x API.

CyberRanger
11-04-2005, 08:33 PM
Well, first off, you didnt define what the member is of in the conditional.. it should be this:

<if condition="is_member_of($bbuserinfo[usergroupid], 9)">Member of Group</if>More words ...Weird ... I'd say you are absolutely correct but oddly my conditional does work like that!? Maybe it defaults to usergroupid??

Edit - if you check out the bottom of this page (http://www.vbulletin.com/docs/html/main/functions_in_conditionals) that is the correct usage to search both the primary and secondary groups. :surprised:

TyleR
11-05-2005, 02:59 AM
hmm...weird..because mine worked and yours didnt for me on both my 3.5.0 and a private 3.0.10

CyberRanger
11-07-2005, 02:47 PM
hmm...weird..because mine worked and yours didnt for me on both my 3.5.0 and a private 3.0.10Yeah, that is weird. But, that was just an example. Anyone know how to do what I originally requested? (besides the create a template example I showed above?)

To restate the question:

I'm pulling text from a database table. The text contains template conditional code. All of the text is placed in a variable.

That variable is then called in a template. When the template is evaluated, the conditional is being ignored. Any ideas on how to make the conditional work in this situation?