PDA

View Full Version : If custom field is set to x then do y


eviljoker7075
01-29-2013, 02:36 PM
Hi, I have setup a radio button custom field. In my postbit template I'd like to add some code that shows a line of text next to each users post depending on what option they have selected in the custom field.

Basically the logic is:
If the user who made this post has option 1 set then show [this piece of code]. If they have option 2 selected then show [this other piece of code].

Can anyone help me write that?

kh99
01-29-2013, 03:12 PM
It should be something like:
<vb:if condition="$post['fieldX'] == 1">
Something
<vb:else />
Something else
</vb:if>



and of course you'd use the actual field number in place of X.

eviljoker7075
01-29-2013, 03:33 PM
Thanks for the quick response, I can't seem to get that code working though. Here's what I have:

A custom field, of 'single-selection radio button' type. It has three options 'one', 'two' and 'three.

The code I added to my postbit template:
<vb:if condition="$post['field13'] == 1">
One selected
<vb:if condition="$post['field13'] == 2">
Two selected
<vb:else />
Something other than one or two selected
</vb:if>

I have got option 1 ('one') selected but the test that's returned in the page is "Something other than one or two selected"

kh99
01-29-2013, 03:53 PM
Oh, right. If the options are 'one', 'two' and 'three' then you have to check for those strings, like

<vb:if condition="$post['field13'] == 'one'">
One selected
<vb:elseif condition="$post['field13'] == 'two'" />
Two selected
<vb:else />
Something other than one or two selected
</vb:if>


Edit: also there's an elseif you can use, I changed the above to show how you'd use it.

eviljoker7075
01-29-2013, 04:04 PM
Ah, sorry I should have been clearer from the start. I also noticed I'd nested my if statements incorrectly. The final snippet I used looks like:

<vb:if condition="$post['field13'] == 'One'">
One selected
</vb:if>

Thanks very much :)