K
New Member
Posts: 2
inherit
258881
0
Jan 16, 2023 15:14:12 GMT -8
K
2
July 2019
questionmark
|
Post by K on Jul 11, 2019 14:49:31 GMT -8
What I want is...
If the field value of 'Relationship Status' is Single (it's a drop down so no extra spaces should screw it up), then it does NOT show the value of 'Relationship With' even if its filled out. Below is the code part I used, but no matter what it seems to not show the 'Relationship With' value even when it isn't 'Single'.
{foreach $[user.mini_custom_field]} {if $[user.mini_custom_field.name] == "Relationship Status"} {if $[user.mini_custom_field.value] == "Single"} $[user.mini_custom_field.value] {else} $[user.mini_custom_field.value] {foreach $[user.mini_custom_field]} {if $[user.mini_custom_field.name] == "Relationship With"} $[user.mini_custom_field.value] {/if} {/foreach} {/if} {/if} {/foreach}
|
|
#eb7100
33409
0
1
Apr 14, 2024 15:59:10 GMT -8
Brian
48,129
November 2004
smashmaster3
|
Post by Brian on Jul 11, 2019 16:19:50 GMT -8
A foreach loop only evaluates against one index of the variable you're going through at a time, so it's not possible to make the display of one custom field dependent on the value of another because $[user.mini_custom_field] can only represent one custom field at a time, and thus $[user.mini_custom_field.name] can only output the name of one custom field throughout the entire foreach block. In addition, it's not possible to start another foreach loop on the same variable while still inside of the previous foreach block like you're attempting to do in the code you posted because once you're inside the block the variable no longer represents the entire list of custom fields you have filled out. It now represents whichever custom field the loop is currently looking at. In more technical terms: - $[user.mini_custom_field] is an array variable, so it can be looped through using {foreach}
- Once inside a foreach loop, $[user.mini_custom_field] now represents the data stored in the current index of the array instead of representing the array itself
- Since $[user.mini_custom_field] is no longer treated as an array variable while inside the loop it's not possible to begin another foreach loop on it until you've exited the foreach block
I went a bit more in-depth in a similar thread not too long ago about how foreach loops work. You can read it here: support.proboards.com/thread/656930/user-custom-field-conditionals
|
|
K
New Member
Posts: 2
inherit
258881
0
Jan 16, 2023 15:14:12 GMT -8
K
2
July 2019
questionmark
|
Post by K on Jul 11, 2019 18:52:32 GMT -8
Ah, I think I understand it - which means what I want to do isn't possible, which is okay. I'll just inform people not to put anything down in the Relationship With area if they choose the Single option. I appreciate your help!
|
|