PDA

View Full Version : using VB:VAR within a conditional?


Trek
12-29-2009, 01:42 AM
Everytime I try this I get a parse error when I save the template. I have no idea what I'm doing wrong, but it's probably something pretty simple/stupid. Here's an example:

<table class="tborder" cellpadding="{vb:stylevar cellpadding}" cellspacing="{vb:stylevar cellspacing}" border="0" width="100%">
<tr>
<td class="thead" width="100%" <vb:if condition="{vb:raw caneditforms}">colspan="2"</vb:if>>{vb:phrase title}</td>
</tr>

I get the following error when saving the template:

The following error occurred when attempting to evaluate this template:
Parse error: syntax error, unexpected '{' in /home/XXXXXX/public_html/XXXXXXX/includes/adminfunctions_template.php(4597) : eval()'d code on line 3

I've tried this on several templates so it's obviously doing something wrong, I just don't know what. =)

Thanks for your help!

BBR-APBT
12-29-2009, 02:14 AM
You do not use {vb:raw var} in conditionals

<vb:if condition="can_moderate()">colspan="2"</vb:if>

Trek
12-29-2009, 02:28 AM
You do not use {vb:raw var} in conditionals

<vb:if condition="can_moderate()">colspan="2"</vb:if>

So even if I'm checking my own custom variable I would use:


<vb:if condition="my_custom_var()">colspan="2"</vb:if>

?? Seems weird, but whatever works!

BBR-APBT
12-29-2009, 03:12 AM
So even if I'm checking my own custom variable I would use:




?? Seems weird, but whatever works!

my_custom_function() would be a function so if you made your own function my_custom_function() would be correct.

So for a custom variable it would be.
if $customvar is set:
<vb:if condition="$customvar">Show this</vb:if>

If $customvar equals:
<vb:if condition="$customvar == blah">Show this if $customvar equals blah</vb:if>

If $customvar does not equal:
<vb:if condition="$customvar != blah">Show this if $customvar does not equal blah</vb:if>



Check out - https://vborg.vbsupport.ru/showthread.php?p=1941139

Trek
12-29-2009, 04:16 AM
Got it! Thanks much, and I rated your other thread 5 stars and subbed to it.