inherit
133146
0
Jan 7, 2024 2:07:03 GMT -8
Alanna 🥀🖤
3,564
November 2008
alannab
|
Post by Alanna 🥀🖤 on May 9, 2019 9:36:11 GMT -8
Forum: adoxographyv2.boards.netTheme: Adoxography Co. ( viewable only to staff) I am attempting to use user custom fields to create conditionals. For example, I am adding a custom portfolio section in profiles for staff and some members who either have earned it or purchased the option, so I don't want the coding to show up in all profiles. I have found that this basic IF statement works for a dropdown custom field: {foreach $[user.custom_field]} {if $[user.custom_field.name] == "Profile Portfolio?"} {if $[user.custom_field.value] == "Show"} CONTENT {/if} {/if} {/foreach}
However, all custom fields WITHIN this IF statement do not work. Is there a better way to write this IF statement with the same purpose and function in mind?
|
|
#eb7100
33409
0
1
Mar 27, 2024 18:49:16 GMT -8
Brian
48,128
November 2004
smashmaster3
|
Post by Brian on May 9, 2019 10:57:32 GMT -8
This isn't currently possible without either completely sacrificing custom fields in mini-profiles or having to maintain a long if statement at the start of any foreach loop to ensure that the fields you want to show only show in one place. If you have 20 custom fields filled out in your profile settings the loop is going to go through the code within itself 20 different times and try to render that code 20 times in a row. Code: Result:
In each iteration of the foreach loop $[user.custom_field] is assigned the data pertaining to whichever index of the custom field array the loop has reached. This means that only one if statement checking against $[user.custom_field.name] can ever validate as true within a single iteration of the loop. It's unfortunately not possible to try and circumvent this by doing another {foreach $[user.custom_field]} loop within the existing loop because inside the loop $[user.custom_field] is no longer considered an array and only represents a single field, meaning it can't be looped through. However, you can do a foreach loop through $[user.mini_custom_field] at this point because it's a completely different array. This should achieve what you want, but at the cost of requiring all of the fields you intend to use to be visible in both full profiles and mini-profiles in your custom field settings. So if you want only certain fields to show up within a custom field loop you essentially have to start that loop off with a long if statement that says "only render the content within me if the custom field name matches any of the following strings."
|
|
inherit
133146
0
Jan 7, 2024 2:07:03 GMT -8
Alanna 🥀🖤
3,564
November 2008
alannab
|
Post by Alanna 🥀🖤 on May 9, 2019 11:01:56 GMT -8
I have zero intention of having any of the custom fields display on mini profiles, I only want them to display in full profiles.
I'll try making all interior fields .mini variables and see if that works.
|
|
inherit
133146
0
Jan 7, 2024 2:07:03 GMT -8
Alanna 🥀🖤
3,564
November 2008
alannab
|
Post by Alanna 🥀🖤 on May 9, 2019 11:11:23 GMT -8
Well, it works- but sadly I already hit the limit on foreach loops.
Have to toss that idea out...
Will conditionals be added to V6? Because this feature is a HUGE idea that I have for Adoxography when V6 comes out and without it- a lot of my ideas are impossible.
|
|
#eb7100
33409
0
1
Mar 27, 2024 18:49:16 GMT -8
Brian
48,128
November 2004
smashmaster3
|
Post by Brian on May 9, 2019 11:35:04 GMT -8
If statements are conditionals. Can you go into more detail?
|
|
inherit
133146
0
Jan 7, 2024 2:07:03 GMT -8
Alanna 🥀🖤
3,564
November 2008
alannab
|
Post by Alanna 🥀🖤 on May 9, 2019 11:47:32 GMT -8
Okay, so I know I left out like all of the {foreach} lines on the nested ones, but this is what I am going for. However, I have two main problems: - I hit the foreach loop limit on the second slide so I only have the ability to have one "slide" which is kinda against the point of a slider portfolio.
- According to what you described to me how the foreach/if statements work on Proboards so far, I only have the ability to nest one statement within a foreach loop, but I need to nest two. The conditional for the overall portfolio, and the conditionals for each slide.
Is there any ways around these two issues or is what I am trying to do completely impossible and I should just drop the whole idea? {foreach $[user.custom_field]} {if $[user.custom_field.name] == "Profile Portfolio?"} {if $[user.custom_field.value] == "Show"} <div class="user-portfolio"> <!-- EDITED ISLIDER REMODEL BY TRINITY BLAIR OF ADOXOGRAPHY, DO NOT STEAL http://tympanus.net/codrops/2012/04/30/fluid-css3-slideshow-with-parallax-effect/ --> <div class="sp-slideshow"> <input id="button-1" type="radio" name="radio-set" class="sp-selector-1" checked="checked" /> <label for="button-1" class="button-label-1"></label> <input id="button-2" type="radio" name="radio-set" class="sp-selector-2" /> <label for="button-2" class="button-label-2"></label> {if $[user.mini_custom_field.name] == "Third Slide"} <input id="button-3" type="radio" name="radio-set" class="sp-selector-3" /> <label for="button-3" class="button-label-3"></label> {/if} {if $[user.mini_custom_field.name] == "Fourth Slide"} <input id="button-4" type="radio" name="radio-set" class="sp-selector-4" /> <label for="button-4" class="button-label-4"></label> {/if} {if $[user.mini_custom_field.name] == "Fifth Slide"} <input id="button-5" type="radio" name="radio-set" class="sp-selector-5" /> <label for="button-5" class="button-label-5"></label> {/if} <label for="button-1" class="sp-arrow sp-a1"></label> <label for="button-2" class="sp-arrow sp-a2"></label> <label for="button-3" class="sp-arrow sp-a3"></label> <label for="button-4" class="sp-arrow sp-a4"></label> <label for="button-5" class="sp-arrow sp-a5"></label> <div class="sp-content"> <ul class="sp-slider clearfix"> <li{if $[user.mini_custom_field.name] == "First Slide Background"} style="background-image:url($[user.mini_custom_field.value])"{/if}> <div class="portfolio-item"> <div class="portfolio-image"{if $[user.mini_custom_field.name] == "First Slide Image"} style="background-image:url($[user.mini_custom_field.value])"{/if}></div> <div class="portfolio-info"> <h1> {if $[user.mini_custom_field.name] == "First Slide Link"}<a href="$[user.mini_custom_field.value]">{/if} {if $[user.mini_custom_field.name] == "First Slide Title"}$[user.mini_custom_field.value]{/if} {if $[user.mini_custom_field.name] == "First Slide Link"}</a>{/if} </h1> <h2> {if $[user.mini_custom_field.name] == "First Slide Sub-Title"}$[user.mini_custom_field.value]{/if} </h2> <p> {if $[user.mini_custom_field.name] == "First Slide Description"}$[user.mini_custom_field.value]{/if} </p> </div> </div> </li> <li{if $[user.mini_custom_field.name] == "Second Slide Background"} style="background-image:url($[user.mini_custom_field.value])"{/if}> <div class="portfolio-item"> <div class="portfolio-image"{if $[user.mini_custom_field.name] == "Second Slide Image"} style="background-image:url($[user.mini_custom_field.value])"{/if}></div> <div class="portfolio-info"> <h1> {if $[user.mini_custom_field.name] == "Second Slide Link"}<a href="$[user.mini_custom_field.value]">{/if} {if $[user.mini_custom_field.name] == "Second Slide Title"}$[user.mini_custom_field.value]{/if} {if $[user.mini_custom_field.name] == "Second Slide Link"}</a>{/if} </h1> <h2> {if $[user.mini_custom_field.name] == "Second Slide Sub-Title"}$[user.mini_custom_field.value]{/if} </h2> <p> {if $[user.mini_custom_field.name] == "Second Slide Description"}$[user.mini_custom_field.value]{/if} </p> </div> </div> </li> {if $[user.mini_custom_field.name] == "Third Slide"} <li{if $[user.mini_custom_field.name] == "Third Slide Background"} style="background-image:url($[user.mini_custom_field.value])"{/if}> <div class="portfolio-item"> <div class="portfolio-image"{if $[user.mini_custom_field.name] == "Third Slide Image"} style="background-image:url($[user.mini_custom_field.value])"{/if}></div> <div class="portfolio-info"> <h1> {if $[user.mini_custom_field.name] == "Third Slide Link"}<a href="$[user.mini_custom_field.value]">{/if} {if $[user.mini_custom_field.name] == "Third Slide Title"}$[user.mini_custom_field.value]{/if} {if $[user.mini_custom_field.name] == "Third Slide Link"}</a>{/if} </h1> <h2> {if $[user.mini_custom_field.name] == "Third Slide Sub-Title"}$[user.mini_custom_field.value]{/if} </h2> <p> {if $[user.mini_custom_field.name] == "Third Slide Description"}$[user.mini_custom_field.value]{/if} </p> </div> </div> </li> {/if} {if $[user.mini_custom_field.name] == "Fourth Slide"} <li{if $[user.mini_custom_field.name] == "Fourth Slide Background"} style="background-image:url($[user.mini_custom_field.value])"{/if}> <div class="portfolio-item"> <div class="portfolio-image"{if $[user.mini_custom_field.name] == "Fourth Slide Image"} style="background-image:url($[user.mini_custom_field.value])"{/if}></div> <div class="portfolio-info"> <h1> {if $[user.mini_custom_field.name] == "Fourth Slide Link"}<a href="$[user.mini_custom_field.value]">{/if} {if $[user.mini_custom_field.name] == "Fourth Slide Title"}$[user.mini_custom_field.value]{/if} {if $[user.mini_custom_field.name] == "Fourth Slide Link"}</a>{/if} </h1> <h2> {if $[user.mini_custom_field.name] == "Fourth Slide Sub-Title"}$[user.mini_custom_field.value]{/if} </h2> <p> {if $[user.mini_custom_field.name] == "Fourth Slide Description"}$[user.mini_custom_field.value]{/if} </p> </div> </div> </li> {/if} {if $[user.mini_custom_field.name] == "Fifth Slide"} <li{if $[user.mini_custom_field.name] == "Fifth Slide Background"} style="background-image:url($[user.mini_custom_field.value])"{/if}> <div class="portfolio-item"> <div class="portfolio-image"{if $[user.mini_custom_field.name] == "Fifth Slide Image"} style="background-image:url($[user.mini_custom_field.value])"{/if}></div> <div class="portfolio-info"> <h1> {if $[user.mini_custom_field.name] == "Fifth Slide Link"}<a href="$[user.mini_custom_field.value]">{/if} {if $[user.mini_custom_field.name] == "Fifth Slide Title"}$[user.mini_custom_field.value]{/if} {if $[user.mini_custom_field.name] == "Fifth Slide Link"}</a>{/if} </h1> <h2> {if $[user.mini_custom_field.name] == "Fifth Slide Sub-Title"}$[user.mini_custom_field.value]{/if} </h2> <p> {if $[user.mini_custom_field.name] == "Fifth Slide Description"}$[user.mini_custom_field.value]{/if} </p> </div> </div> </li> {/if} </ul> </div> </div> <!-- END EDITED ISLIDER REMODEL BY TRINITY BLAIR OF ADOXOGRAPHY, DO NOT STEAL --> </div> {/if} {/if} {/foreach}
|
|
inherit
133146
0
Jan 7, 2024 2:07:03 GMT -8
Alanna 🥀🖤
3,564
November 2008
alannab
|
Post by Alanna 🥀🖤 on May 9, 2019 11:50:29 GMT -8
If statements are conditionals. Can you go into more detail? I'm asking if user custom fields will be able to have conditionals, not IF statements. Example of a conditional on a custom field would be: - Field Name: Do you have a Facebook?
- Drop Down Options: Yes, No
- Conditional: If "Yes" show custom field "Facebook Username"
This way, the custom field "Facebook Username" would only display in profiles/mini profiles and edit profile ONLY if the custom field "Do you have a Facebook?" was set to "Yes". Having conditionals for custom fields built in would avoid having to do nested foreach loops and hitting the loop limit.
|
|
#eb7100
33409
0
1
Mar 27, 2024 18:49:16 GMT -8
Brian
48,128
November 2004
smashmaster3
|
Post by Brian on May 9, 2019 13:26:57 GMT -8
According to what you described to me how the foreach/if statements work on Proboards so far, I only have the ability to nest one statement within a foreach loop, but I need to nest two. You can do multiple statements in a single loop, but anything that's a direct child of the loop that exists outside of a statement will be rendered each time the loop is run. Example of a conditional on a custom field would be: - Field Name: Do you have a Facebook?
- Drop Down Options: Yes, No
- Conditional: If "Yes" show custom field "Facebook Username"
This way, the custom field "Facebook Username" would only display in profiles/mini profiles and edit profile ONLY if the custom field "Do you have a Facebook?" was set to "Yes". Having conditionals for custom fields built in would avoid having to do nested foreach loops and hitting the loop limit. I think you need to type out an example of the difference in the code that you would use if your idea were in place because I'm still not seeing how this is any different from how they already work or how it cuts down on how many foreach loops are needed.
|
|
inherit
133146
0
Jan 7, 2024 2:07:03 GMT -8
Alanna 🥀🖤
3,564
November 2008
alannab
|
Post by Alanna 🥀🖤 on May 9, 2019 15:49:56 GMT -8
According to what you described to me how the foreach/if statements work on Proboards so far, I only have the ability to nest one statement within a foreach loop, but I need to nest two. You can do multiple statements in a single loop, but anything that's a direct child of the loop that exists outside of a statement will be rendered each time the loop is run. If you take a look at the code I provided, you can see why this method simply does not work for my design. If a plugin can be created in order to get around the foreach loop limit ( host all the loops in the plugin rather than the layout template- for example), that would be amazing and exactly what I need since the current system is too limited for the idea I have in mind. Example of a conditional on a custom field would be: - Field Name: Do you have a Facebook?
- Drop Down Options: Yes, No
- Conditional: If "Yes" show custom field "Facebook Username"
This way, the custom field "Facebook Username" would only display in profiles/mini profiles and edit profile ONLY if the custom field "Do you have a Facebook?" was set to "Yes". Having conditionals for custom fields built in would avoid having to do nested foreach loops and hitting the loop limit. I think you need to type out an example of the difference in the code that you would use if your idea were in place because I'm still not seeing how this is any different from how they already work or how it cuts down on how many foreach loops are needed. The difference would be that I wouldn't have to nest a bunch of foreach and if statements manually in the layout templates as it would all be done within the forum's built in coding when the fields are created in the admin panel. Currently I cannot set a custom field to show ONLY if another field has a specific value- that is what I am suggesting. Honestly I'm surprised you are having a difficult time picturing or understanding conditionals for custom fields.
|
|
#eb7100
33409
0
1
Mar 27, 2024 18:49:16 GMT -8
Brian
48,128
November 2004
smashmaster3
|
Post by Brian on May 9, 2019 17:56:18 GMT -8
If you take a look at the code I provided, you can see why this method simply does not work for my design. If a plugin can be created in order to get around the foreach loop limit ( host all the loops in the plugin rather than the layout template- for example), that would be amazing and exactly what I need since the current system is too limited for the idea I have in mind. The method I provided earlier combined with creative application of CSS can take the layout pretty far on the surface, but when 10 different fields (namely the slide image ones) need to affect very specific descendants way deeper in there's not much that can be done to circumvent that using the layout templates alone. I would highly recommend a JavaScript-based solution for this considering how spread out all of the things reliant on custom fields are. Since each slide appears to use the exact same HTML you could store all of the finer details within data attributes and access/apply them using JS when the page loads. If a field contains a large block of text or something that can potentially break out of an HTML attribute it could go in a hidden element that can be accessed and moved into the appropriate spot later. Currently I cannot set a custom field to show ONLY if another field has a specific value- that is what I am suggesting. This part had already registered from the very beginning of the thread which is why I was able to definitively say "this isn't currently possible" and proposed the solution that I did. Honestly I'm surprised you are having a difficult time picturing or understanding conditionals for custom fields. You lost me at "Will conditionals be added to v6?" because by definition if statements are conditionals and already exist. I kept coming back to that baseline trying to wrap my head around why an existing feature was being requested and didn't realize the question actually meant "Will I be able to nest custom field conditionals within one another without the use of multiple foreach loops?" In an ideal future custom fields would have their own standalone variables that don't need to be accessed from a loop at all but I'm not aware of any plans for anything like that at the moment.
|
|