Is it possible to nest a <vb:if> conditional inside a <vb:each>?
Here is what I am trying to accomplish:
Code:
<vb:each from="full_list" value="list">
<tr>
<td>{vb:raw list['char_name']} </td>
<td>
{vb:raw list['class_1_name']}({vb:raw list['class_1_level']})
<vb:if condition="full_list.class_2 != 0">
, {vb:raw list['class_2_name']}({vb:raw list['class_2_level']})
</vb:if>
<vb:if condition="full_list.class_3 != 0">
, {vb:raw list['class_3_desc']}({vb:raw list['class_3_level']})
</vb:if>
</td>
</tr>
</vb:each>
The desired output would be something like
Code:
Char Name Class1 Name(10), Class2 Name(3)
Char Name Class1 Name(5)
Char Name Class1 Name(15), Class2 Name(3), Class3 Name(2)
The tables field value is default to NULL, so maybe i need to change it to force default of 0, or NONE. (this just came to me as im preparing to leave for the day, so i have not tried this out yet).
Any help would be appreciated. I've tried things like != '0', != NULL, != 'NULL', !='', etc. I've also tried various syntax for the 'full_list.class_3' part of the if conditional, no joy.
--------------- Added [DATE]1298499736[/DATE] at [TIME]1298499736[/TIME] ---------------
Looks like I posted prematurely again! Hopefully this will help others in the future though.
SOLUTION!
As you can see, i changed up the syntax in the IF conditional. I also took my previous advice and changed the database field from a
DEFAULT NULL to a
DEFAULT '0'.
Code:
<vb:each from="full_list" value="list">
<tr>
<td>{vb:raw list['char_name']} </td>
<td>
{vb:raw list['class_1_name']}({vb:raw list['class_1_level']})
<vb:if condition="$list['class_2_level'] != 0">
, {vb:raw list['class_2_name']}({vb:raw list['class_2_level']})
</vb:if>
<vb:if condition="$list['class_3_level'] != 0">
, {vb:raw list['class_3_desc']}({vb:raw list['class_3_level']})
</vb:if>
</td>
</tr>
</vb:each>