inherit
256084
0
Apr 11, 2020 4:03:43 GMT -8
mysticrystal
74
August 2018
mysticrystal
|
Post by mysticrystal on Feb 6, 2020 2:39:13 GMT -8
So basically what I'm trying to do is make it where if a custom profile text field is not entered then it will just show the number 0. But everytime I try with the code below, it adds 0s everywhere or just doesn't work. I might just be dumb but I really need some help please.
{foreach $[user.mini_custom_field]}{if $[user.mini_custom_field.name] == "MP"} $[user.mini_custom_field.value] {else} 0 {/if}{/foreach}
|
|
inherit
259017
0
Sept 25, 2021 1:54:15 GMT -8
CrazyBoy
Web developer.
968
July 2019
crazyboy
|
Post by CrazyBoy on Feb 6, 2020 3:20:21 GMT -8
I suggest to move {foreach ...}{/foreach} So it won't let the 0 appear each time I hope
|
|
inherit
256084
0
Apr 11, 2020 4:03:43 GMT -8
mysticrystal
74
August 2018
mysticrystal
|
Post by mysticrystal on Feb 6, 2020 3:26:40 GMT -8
Move it where?
|
|
inherit
259017
0
Sept 25, 2021 1:54:15 GMT -8
CrazyBoy
Web developer.
968
July 2019
crazyboy
|
Post by CrazyBoy on Feb 6, 2020 3:38:53 GMT -8
You want all the custom fields to have this option or only for the "MP" custom field ?
|
|
inherit
256084
0
Apr 11, 2020 4:03:43 GMT -8
mysticrystal
74
August 2018
mysticrystal
|
Post by mysticrystal on Feb 6, 2020 4:23:08 GMT -8
|
|
inherit
259017
0
Sept 25, 2021 1:54:15 GMT -8
CrazyBoy
Web developer.
968
July 2019
crazyboy
|
Post by CrazyBoy on Feb 6, 2020 6:57:13 GMT -8
So why you are using the if statment of that name between {foreach}{/foreach} tags ?
|
|
inherit
256084
0
Apr 11, 2020 4:03:43 GMT -8
mysticrystal
74
August 2018
mysticrystal
|
Post by mysticrystal on Feb 6, 2020 7:07:58 GMT -8
Because I have to say which custom field is being used? I know I'm not good at this which is why I'm asking for assistance.
|
|
inherit
259017
0
Sept 25, 2021 1:54:15 GMT -8
CrazyBoy
Web developer.
968
July 2019
crazyboy
|
Post by CrazyBoy on Feb 6, 2020 7:10:33 GMT -8
Because I have to say which custom field is being used? I know I'm not good at this which is why I'm asking for assistance. I still asking also. But this os fine From the code I see it says. Each time you see custom field and if a name is MP else set to 0. Which you may set to 0 before the else This causes problems I currently with phone untill 19 so I can test a code in my mind
|
|
inherit
256084
0
Apr 11, 2020 4:03:43 GMT -8
mysticrystal
74
August 2018
mysticrystal
|
Post by mysticrystal on Feb 6, 2020 7:12:55 GMT -8
I'm sorry, but I don't know what you mean. If you can help me with the code, please do whenever possible. If not, thank you and hopefully someone else is able to help me.
|
|
#eb7100
33409
0
1
Nov 24, 2024 4:27:37 GMT -8
Brian
48,130
November 2004
smashmaster3
|
Post by Brian on Feb 6, 2020 11:25:15 GMT -8
This isn't currently possible to achieve.
When a custom field hasn't been filled out in your profile settings it's not included in the array of objects the foreach loop goes through, so none of the if statements included inside the loop will ever see it.
For example, if you have custom fields named A, B, and C and you only fill out A and C in your Edit Profile page this foreach loop will only output the names of fields A and C:
Result:
Field B was never filled out, so it was never included in the loop.
|
|
inherit
256084
0
Apr 11, 2020 4:03:43 GMT -8
mysticrystal
74
August 2018
mysticrystal
|
Post by mysticrystal on Feb 6, 2020 14:47:37 GMT -8
|
|
Kami
Forum Cat
Posts: 40,201
Mini-Profile Theme: Kami's Mini-Profile
#f35f71
156500
0
Offline
Jul 24, 2021 11:48:29 GMT -8
Kami
40,201
July 2010
kamiyakaoru
Kami's Mini-Profile
|
Post by Kami on Feb 6, 2020 16:13:59 GMT -8
You can sort of work around this by using CSS and if/else.
I'd have to dig into it more when I'm at home, but basically you can put text inside a div or a span with a class name surrounded by if/else tags, eg:
<span {if $[user.mini_custom_field.name] == "Field C"}style="display: none;"{/if}>0</span>
Then style="display: none;" will appear only if the condition is true. If the field doesn't exist, it can't match the IF condition and will therefore display the 0. If it does exist, it will hide the 0.
|
|
inherit
256084
0
Apr 11, 2020 4:03:43 GMT -8
mysticrystal
74
August 2018
mysticrystal
|
Post by mysticrystal on Feb 7, 2020 15:57:19 GMT -8
Kami Whenever you get the chance to dig into it more, please let me know. I tried to use the code but it always says 0.
|
|
#eb7100
33409
0
1
Nov 24, 2024 4:27:37 GMT -8
Brian
48,130
November 2004
smashmaster3
|
Post by Brian on Feb 7, 2020 18:07:44 GMT -8
I think Kami's suggestion works under the assumption that the foreach loop is going to run for every field. But because the loop ignores fields that aren't filled out it runs into the same problem as before.
You can get around all of the issues presented so far through the use of JavaScript to add new elements to the page when one that you specify is detected as missing, but then you're using JavaScript and running code for every post on the page. JavaScript has to do all of its calculations client-side and do the heavy lifting on the member's computer so it might increase page rendering time. But it'd work!
|
|
Kami
Forum Cat
Posts: 40,201
Mini-Profile Theme: Kami's Mini-Profile
#f35f71
156500
0
Offline
Jul 24, 2021 11:48:29 GMT -8
Kami
40,201
July 2010
kamiyakaoru
Kami's Mini-Profile
|
Post by Kami on Feb 7, 2020 19:04:58 GMT -8
I think Kami's suggestion works under the assumption that the foreach loop is going to run for every field. But because the loop ignores fields that aren't filled out it runs into the same problem as before. You can get around all of the issues presented so far through the use of JavaScript to add new elements to the page when one that you specify is detected as missing, but then you're using JavaScript and running code for every post on the page. JavaScript has to do all of its calculations client-side and do the heavy lifting on the member's computer so it might increase page rendering time. But it'd work! you could still do this with if/else, you would just have to get really granular with the custom fields. I have a working example on another forum so i'll pop that in here over the weekend (:
|
|