Mewwn
New Member
Posts: 11
inherit
254990
0
Dec 20, 2018 7:42:44 GMT -8
Mewwn
11
May 2018
mewwn
|
Post by Mewwn on May 23, 2018 12:02:56 GMT -8
Heya! I have a question regarding the {if} statements used. How can I have proboards check for an empty value in a custom profile field or profile setting such as 'Custom Title'?
For example, is there a way that if nobody has the "Species" field filled, can I simply make it state "None" if the user in which the mini-profile is displaying hasn't filled out the "Species" field?
<span class="charspecies">
{foreach $[user.custom_field]}
{if $[user.custom_field.name] == "Species"}
<span class="$[user.custom_field.content_class]">
$[user.custom_field.value]</span>
{/if}
{/foreach}
</span>
|
|
inherit
223470
0
Feb 27, 2019 17:05:53 GMT -8
₪» ⅀ ƪ Ƒ «₪
Original registration date: 2007. DeviantART: http://deviantart.com/ruanly. Discord: Ruanly#7946.
1,281
July 2015
fajita
|
Post by ₪» ⅀ ƪ Ƒ «₪ on May 24, 2018 19:18:23 GMT -8
Unfortunately, this isn't currently possible to my knowledge. It has been often requested and I know many people, myself included, desperately want this. But admins have told me in the past that it isn't possible for reasons I do not personally know. I've asked several times ever since V5 was released years ago and the answer has never changed and they've never indicated if it'll ever be possible. I've waited many years so... fingers crossed, maybe in V6. :(
I will say I've found really rough workarounds that suck because it very quickly eats at your small foreach loop limit, but I set up my code how I want it to look if there isn't anything in the field, then I code the custom field with a solid background and use negative margins to drag it over the "none." So basically if there isn't a custom field entry, it shows the default "none" that I falsely coded in there myself. If there is a custom field entry, I have it overlap and thus hide it. It can be messy and you run out of foreach loops fast but it does work
|
|
Mewwn
New Member
Posts: 11
inherit
254990
0
Dec 20, 2018 7:42:44 GMT -8
Mewwn
11
May 2018
mewwn
|
Post by Mewwn on May 24, 2018 21:42:23 GMT -8
Unfortunately, this isn't currently possible to my knowledge. It has been often requested and I know many people, myself included, desperately want this. But admins have told me in the past that it isn't possible for reasons I do not personally know. I've asked several times ever since V5 was released years ago and the answer has never changed and they've never indicated if it'll ever be possible. I've waited many years so... fingers crossed, maybe in V6. I will say I've found really rough workarounds that suck because it very quickly eats at your small foreach loop limit, but I set up my code how I want it to look if there isn't anything in the field, then I code the custom field with a solid background and use negative margins to drag it over the "none." So basically if there isn't a custom field entry, it shows the default "none" that I falsely coded in there myself. If there is a custom field entry, I have it overlap and thus hide it. It can be messy and you run out of foreach loops fast but it does work Thanks for the help, I appreciate it! It's upsetting what I intended isn't quite possible, but it won't be the end of the world. Your explanation is interesting, though. May I ask for clarification on how you get that sort of thing into a form of code regarding how you make the forum tell the difference if there's something in the custom field versus nothing? Unless I'm misunderstanding, because from what I got from your first paragraph, you can't make PB distinguish such a thing.
|
|
inherit
223470
0
Feb 27, 2019 17:05:53 GMT -8
₪» ⅀ ƪ Ƒ «₪
Original registration date: 2007. DeviantART: http://deviantart.com/ruanly. Discord: Ruanly#7946.
1,281
July 2015
fajita
|
Post by ₪» ⅀ ƪ Ƒ «₪ on May 25, 2018 5:21:09 GMT -8
Sure, let me write an example. :) So let's say I have a field called Age. I have my members enter their character's age into this box, like "4," but I want it to show up "N/A" if they don't enter their age instead of just not showing at all. In a really bare-bones, minimal example just to be clear with it, I would start first by making my "N/A" by hand. This isn't actually automatic, it is always there, it just gets hidden if there is an age. Then I would create a foreach loop, an if statement targeting the age custom field, and drag it over. So this is a bare-bones code example: <b>N/A</b>
{foreach $[user.custom_field]} {if $[user.custom_field.name] == "Age"} <div style="position: relative; top: -13px; padding-top: 3px; margin-bottom: -12px; height: 18px; text-align: center; background-color: #948263;">$[user.custom_field.value]</div> {/if} {/foreach} So what this does is I use position relative, top, padding-top, margin-bottom, height, and other measurement codes to drag the age entry on top of my N/A and the reason that the N/A is completely hidden then is because I added a background color. So the background color completely covers the N/A and then the entered age value looks like the only value there is. This doesn't sense if there "isn't" a field. It simply applies an effect if there IS a field, which is what custom profile fields are intended to do. By using this roundabout overlapping method, I can pretend it senses that there isn't an age when, in reality, it is constantly saying N/A and I simply hide it when someone enters their age. If you decide to try this kind of route with yours, the positive/top/padding-top/margin-bottom/height/etc will vary. Those were measurements I used on my forum for a specific area and those happened to be the numbers I needed to get it correctly positioned. You will probably have to move it around on your forum to find the sweet spot if you choose to pursue this. Plus you need to change the background color to be identical to the background that it's trying to camouflage. Here is 1 way I used this on my site. I have an "Attendance" box - it means if they are on hiatus or not. By default, my "attendance" box says N/A like this: If a member enters a hiatus, then it looks like this: The entire "Away until 01/01/2016" that you see is really just covering up the N/A with an identical brown box. Sorry for rambling, I don't know if I was clear so I was trying to say it in different ways in case what I was saying was confusing. Let me know if you have any further questions, of course!
|
|
Mewwn
New Member
Posts: 11
inherit
254990
0
Dec 20, 2018 7:42:44 GMT -8
Mewwn
11
May 2018
mewwn
|
Post by Mewwn on May 25, 2018 10:49:49 GMT -8
I believe I understand, now, thank you so much! Don't be sorry for rambling, it was extremely helpful. I gave it a shot, and it is indeed a working method to what I initially had in mind. Again, thank you so much for your help!
|
|
inherit
223470
0
Feb 27, 2019 17:05:53 GMT -8
₪» ⅀ ƪ Ƒ «₪
Original registration date: 2007. DeviantART: http://deviantart.com/ruanly. Discord: Ruanly#7946.
1,281
July 2015
fajita
|
Post by ₪» ⅀ ƪ Ƒ «₪ on May 25, 2018 10:51:53 GMT -8
You're very welcome! Let me know if you wind up with any questions later down the road. I'm really happy it's working for you =D The foreach limit is something like 30 just so you know, since this method requires a separate foreach loop for every custom field it runs out fast, so keep that in mind as you go :)
|
|
Kami
Forum Cat
Posts: 40,064
Mini-Profile Theme: Kami's Mini-Profile
#f35f71
156500
0
Offline
Jul 24, 2021 11:48:29 GMT -8
Kami
40,064
July 2010
kamiyakaoru
Kami's Mini-Profile
|
Post by Kami on Jun 4, 2018 11:35:34 GMT -8
₪» ⅀ ƪ Ƒ «₪ - I'm not sure why you would need to use a foreach loop for every single iteration of this? if you used the foreach loop in combination with if/else statements you can cut down on the number of loops in your template. so for example {foreach $[user.custom_field]} {if $[user.custom_field.name] == "Thing 1"} content here {elseif $[user.custom_field.name] == "Thing 2"} content here {elseif $[user.custom_field.name] == "Thing 3"} content here . . . (and so on) {/foreach} So if you have 20 custom fields you can still use just one foreach loop to with 1 if and 19 elseifs. The 'foreach' loop simply states that each 'user custom field' needs to follow whatever is dictated, but the further clarification of 'if' it's specificially X or 'else if' it's specifically Y makes it so that you can control what content appears.
|
|
inherit
223470
0
Feb 27, 2019 17:05:53 GMT -8
₪» ⅀ ƪ Ƒ «₪
Original registration date: 2007. DeviantART: http://deviantart.com/ruanly. Discord: Ruanly#7946.
1,281
July 2015
fajita
|
Post by ₪» ⅀ ƪ Ƒ «₪ on Jun 4, 2018 11:37:41 GMT -8
The reason I personally need to use a foreach is because I make a container for a specific field, for example on my forum I use a custom profile field for age. I have a table with two rows, so the top is age, the bottom is the number. If they don't have an age, I want it to be N/A, if they enter an age, then the custom profile field covers it up. If I don't put a foreach specifically in that TD, it won't show up every time regardless if they have an age entered or not. I don't know if that makes sense - but that's why I have to use a foreach for each one. Because if I have multiple custom profile fields in the same loop, it doesn't function the way I need it to.
|
|
Kami
Forum Cat
Posts: 40,064
Mini-Profile Theme: Kami's Mini-Profile
#f35f71
156500
0
Offline
Jul 24, 2021 11:48:29 GMT -8
Kami
40,064
July 2010
kamiyakaoru
Kami's Mini-Profile
|
Post by Kami on Jun 4, 2018 13:07:30 GMT -8
The reason I personally need to use a foreach is because I make a container for a specific field, for example on my forum I use a custom profile field for age. I have a table with two rows, so the top is age, the bottom is the number. If they don't have an age, I want it to be N/A, if they enter an age, then the custom profile field covers it up. If I don't put a foreach specifically in that TD, it won't show up every time regardless if they have an age entered or not. I don't know if that makes sense - but that's why I have to use a foreach for each one. Because if I have multiple custom profile fields in the same loop, it doesn't function the way I need it to. Ew tables :P Fair enough. I feel like there should be a cleaner way to do this but it just might not be possible. I might look into it when I have the time and will PM you if I find something (:
|
|
inherit
223470
0
Feb 27, 2019 17:05:53 GMT -8
₪» ⅀ ƪ Ƒ «₪
Original registration date: 2007. DeviantART: http://deviantart.com/ruanly. Discord: Ruanly#7946.
1,281
July 2015
fajita
|
Post by ₪» ⅀ ƪ Ƒ «₪ on Jun 4, 2018 13:38:07 GMT -8
Yeah unfortunately it's all I've found. It works perfectly, it just has its restrictions =/ Awesome, let me know if you ever find another route!
|
|
#eb7100
33409
0
1
May 16, 2024 19:58:36 GMT -8
Brian
48,129
November 2004
smashmaster3
|
Post by Brian on Jun 5, 2018 8:14:22 GMT -8
As far as I know the only method other than creating a series of foreach loops in the template is to use Javascript to add in your preferred "None" text after the page has already loaded. It gets the job done at the cost of the user's browser having to perform more work before the page fully loads and thus slowing down their page load time.
Alternatively, if it's just text you're looking to add you can format the foreach loop a certain way and use CSS to check if the element containing the loop is completely empty, but I don't really recommend this. You have to make the template look super ugly to get this to work and the text wouldn't be able to be highlighted by the mouse cursor like text that's part of the DOM.
|
|