inherit
114253
0
Sept 23, 2024 7:58:54 GMT -8
Teg
Can't Wait for V6
3,157
November 2007
teg
|
Post by Teg on Sept 20, 2024 15:37:53 GMT -8
Is there a way to set a default value for a custom field so that if the user or staff member doesn't out anything in it, it displays something by default?
|
|
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 Sept 21, 2024 7:49:11 GMT -8
Is there a way to set a default value for a custom field so that if the user or staff member doesn't out anything in it, it displays something by default? Nope. Custom fields do not even appear (no data for the field including the name) if there is no value in the profile. The best way I've found to fake this effect is to hard code the field in the templates including the field name. Then I have a span with my default value, and a class OR an inline css wrapped in a conditional statement calling out the custom field name, and saying if there is a value in the field to display the class. Then set the css for the class or inline to display:none; I don't remember the specific syntax and I'm on my phone but if you can't figure it out from this description I can help on Monday when I'm back at my desk :)
|
|
inherit
114253
0
Sept 23, 2024 7:58:54 GMT -8
Teg
Can't Wait for V6
3,157
November 2007
teg
|
Post by Teg on Sept 21, 2024 9:01:10 GMT -8
I had initially tried to do something like this:
{foreach $[user.custom_field]} {if $[user.custom_field.name] == "House Points"} <tr> <td class="field">House Points:</td> <td class="value">{if $[user.custom_field.value] < 1}0{else}$[user.custom_field.value]{/if}</td> </tr> {/if} {/foreach}
Which, obviously didn't work. I even tried an alpha numeric field with == "' or == " " So, yeah, I'm stuck lol
|
|
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 Sept 21, 2024 11:11:39 GMT -8
I had initially tried to do something like this: {foreach $[user.custom_field]} {if $[user.custom_field.name] == "House Points"} <tr> <td class="field">House Points:</td> <td class="value">{if $[user.custom_field.value] < 1}0{else}$[user.custom_field.value]{/if}</td> </tr> {/if} {/foreach}
Which, obviously didn't work. I even tried an alpha numeric field with == "' or == " " So, yeah, I'm stuck lol Yeah that's not what I said to do, sorry for any confusion. You cannot use conditionals that require the field to exist first as you have it here (you have it set to IF this appears THEN do something; it must exist before the conditional is checked). You have to do it backward. So, like this: Field Name: <span {if $[user.custom_field.name] == "NAME"}style="display:none;"{/if}>Default Text</span> {if $[user.custom_field.name] == "NAME"}$[user.custom_field.value]{/if} "Default Text" appears as hard coded text. If the field is filled with a value, the field appears and can be referenced, which will trigger the css to appear, hiding the hard coded text and displaying the field value by itself. Do NOT put it in the foreach loop.
|
|
inherit
114253
0
Sept 23, 2024 7:58:54 GMT -8
Teg
Can't Wait for V6
3,157
November 2007
teg
|
Post by Teg on Sept 21, 2024 14:50:15 GMT -8
I definitely misread what you wrote initially. I will try that when I’m back at my desk later tonight! Thanks Kami
|
|