PDA

View Full Version : if condition problem


micheal332001
24 Nov 2009, 10:58
I have a problem with this

<vb:if condition="$gameinfo[uid] == $userid">i have both these vars in the PHP file and show when i put print but they dont work in the html if condition statment.

If i put this in like so

<vb:if condition="{vb:var gameinfouid}you get an error page show when trying to save the template.

Could you please let me know how to get my vars to work in the new template system.

$gameinfo[uid] == $userid

Paul M
24 Nov 2009, 12:21
Have you registered the variables for use in the template ?

micheal332001
24 Nov 2009, 12:39
Have you registered the variables for use in the template ?

you cannot use this {vb:var gameinfouid} in a if statment you will get errors when saving the template.

ragtek
24 Nov 2009, 12:46
I think you have to make the second condition on php side;)


if (gameinfo[uid] == $userid)
{
$show['foo'] == true;
}

And then in template

<vb:if condition="$show['foo']">

xman_79
24 Nov 2009, 13:02
why not use in your php file


$show['something'] = iif($gameinfo[uid] == $userid , true , flase);



and in your template


<vb:if condition="$show['something']">
html code ....
</vb:if>


Edit : excuse me ragtek I saw your answer later

ragtek
24 Nov 2009, 13:23
I wouldn't use iif, use instead the ternary operator because iif is deprecated;)
// #############################################################################
/**
* Essentially a wrapper for the ternary operator.
*
* @deprecated Deprecated as of 3.5. Use the ternary operator.
*
* @param string Expression to be evaluated
* @param mixed Return this if the expression evaluates to true
* @param mixed Return this if the expression evaluates to false
*
* @return mixed Either the second or third parameter of this function
*/
function iif($expression, $returntrue, $returnfalse = '')


$show['foo'] = ($gameinfo['id'] == $userid ? true: false);

micheal332001
24 Nov 2009, 14:09
why not use in your php file


$show['something'] = iif($gameinfo[uid] == $userid , true , flase);

and in your template


<vb:if condition="$show['something']">
html code ....
</vb:if>
Edit : excuse me ragtek I saw your answer later

I have tryed this and if i put a echo or print on the $show['something'] it will show if its true or flase,
but in the template its not seeing it and outputting the info its showing it as $show['something'].

here is my PHP code



$show['something'] = iif($gameinfo[uid] == $userid , true , flase);

$templater = vB_Template::create('gamesswap_left_block_bit');
$templater->register('lm_catslist', $lm_catslist);
$templater->register('lm_myaccount', $lm_myaccount);
$left_block .= $templater->render();

$templater = vB_Template::create('gamesswap_featured_block_bit');
$templater->register('cb_newestgames', $cb_newestgames);
$templater->register('cb_topseller', $cb_topseller);
$featured_block .= $templater->render();

$templater = vB_Template::create('gamesswap_view_game_page_bit');
$templater->register('gname', $gameinfo[gname]);
$templater->register('gimage', $gameinfo[image]);
$templater->register('gdescription', $gdescription);
$templater->register('gaurther', $gameinfo[aurther]);
$templater->register('gpub', $gameinfo[pub]);
$templater->register('gameregion', $gameregion);
$templater->register('gcondition', $gameinfo[condition]);
$templater->register('ggage', $gameinfo[gage]);
$templater->register('ginstructions', $gameinfo[instructions]);
$templater->register('pictures', $pictures);
$templater->register('gswap1', $swaplist[swap1]);
$templater->register('gswap2', $swaplist[swap2]);
$templater->register('gswap3', $swaplist[swap3]);
$templater->register('gswap4', $swaplist[swap4]);
$templater->register('gswap5', $swaplist[swap5]);
$templater->register('gswap6', $swaplist[swap6]);
$templater->register('swap_status', $gameinfo[swap_status]);
$templater->register('gid', $gameinfo[gid]);
$current .= $templater->render();

$templater = vB_Template::create('gamesswap');
$templater->register_page_templates();
$navbits = construct_navbits(array("gamesswap.php?" . $vbulletin->session->vars['sessionurl'] => $page_title));
$navbar = render_navbar_template($navbits);
$templater->register('navbar', $navbar);
$templater->register('page_title', $page_title);
$templater->register('current', $current);
$templater->register('cm_catslist', $cm_catslist);
$templater->register('left_block', $left_block);
$templater->register('lm_search', $lm_search);
$templater->register('featured_block', $featured_block);
print_output($templater->render());

Here is my template code



<vb:if condition="$show['something']">
<vb:else />
<table border="0" width="100%" align="center">
<tr>
<td colspan="2" class="blocksubhead" width="50%" align="center">{vb:raw vbphrase.options}</td>
</tr>
<tr>
<td class="alt1" width="50%" align="center"><vb:if condition="$swap_status1 > 1">
{vb:raw swap_status}
<vb:else />
<form action="gamesswap.php?do=swap" method="post" enctype="multipart/form-data" target="_self">
<input type="hidden" name="gid" value="{vb:raw gid}">
<input type="submit" value="{vb:raw vbphrase.gamesswap_view_game_swap}">
</form>
</vb:if>
</td>
<td class="alt1" width="50%" align="center">
<form action="gamesswap.php?do=question" method="post" enctype="multipart/form-data" target="_self">
<input type="hidden" name="gid" value="{vb:raw gid}">
<input type="submit" value="{vb:raw vbphrase.gamesswap_view_game_question}">
</form>
</td>
</tr>
</table>
</vb:if>

But the if statment is still not working.