inherit
Head of the Emu Preservation
Head of the Emu Farmers Association
13398
0
Jul 12, 2020 14:15:37 GMT -8
Joshua Farrell
7,966
September 2003
dentist
|
Post by Joshua Farrell on May 13, 2019 12:08:47 GMT -8
So, I couldn't figure this one out. It is easy enough to do one if, then else statement based on board ID or post count, but I couldn't figure out how to combine both if, else statements into one.
Basically I want to be able to show the create topic button for a specific board (Advertising board), only if it is that board, and by also having a certain post count before it shows.
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,017
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on May 13, 2019 12:41:37 GMT -8
You could just go hardcore with board permissions and kill two dragons with one balista ..or follow the script and employ the "&&" to ensure two things must be true before the conditional proceeds (remembering that mobile users do not follow the script just yet unless you force desktop version on them)
|
|
inherit
96289
0
May 17, 2020 9:37:00 GMT -8
elli
1,822
January 2007
ebbymac
|
Post by elli on May 13, 2019 12:49:52 GMT -8
You can combine conditional statements using operators. However, based on this thread it doesn't sound like it's possible to compare post count directly. You can compare ranks, though the downside to this is that you have to include the name of each rank above the desired post count. For example, in Admin > Layout Templates > Board: {if $[create_thread_button]} {if $[board.id] == 9 && $[current_user.rank.name] == "rank1" && $[current_user.rank.name] == "rank2"} <ul class="controls"><li>$[create_thread_button]</li></ul> {elseif $[board.id] != 9} <ul class="controls"><li>$[create_thread_button]</li></ul> {/if} {/if} Then we need an elseif that excludes the targeted board but includes all others (standard else doesn't work here). Replace "9" with the ID of the targeted board, and "rank1", "rank2" with the names of the ranks that have the desired post counts. EDIT: Chris's solution above would be cleaner and works on the mobile site, as well.
|
|
inherit
Head of the Emu Preservation
Head of the Emu Farmers Association
13398
0
Jul 12, 2020 14:15:37 GMT -8
Joshua Farrell
7,966
September 2003
dentist
|
Post by Joshua Farrell on May 13, 2019 12:59:09 GMT -8
You could just go hardcore with board permissions and kill two dragons with one balista ..or follow the script and employ the "&&" to ensure two things must be true before the conditional proceeds (remembering that mobile users do not follow the script just yet unless you force desktop version on them) Haha. Completely forgot you can require that on the board settings page. Much better than trying to use a script.
|
|
inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,846
January 2015
msg
|
Post by Lynx on May 18, 2019 10:19:33 GMT -8
You can combine conditional statements using operators. However, based on this thread it doesn't sound like it's possible to compare post count directly. You can compare ranks, though the downside to this is that you have to include the name of each rank above the desired post count. For example, in Admin > Layout Templates > Board: {if $[create_thread_button]} {if $[board.id] == 9 && $[current_user.rank.name] == "rank1" && $[current_user.rank.name] == "rank2"} <ul class="controls"><li>$[create_thread_button]</li></ul> {elseif $[board.id] != 9} <ul class="controls"><li>$[create_thread_button]</li></ul> {/if} {/if} Then we need an elseif that excludes the targeted board but includes all others (standard else doesn't work here). Replace "9" with the ID of the targeted board, and "rank1", "rank2" with the names of the ranks that have the desired post counts. EDIT: Chris's solution above would be cleaner and works on the mobile site, as well. Just a small fix on your code, elli. This line would always return false: {if $[board.id] == 9 && $[current_user.rank.name] == "rank1" && $[current_user.rank.name] == "rank2"}
because a person can't have more than 1 rank at a time. They could never have "rank1" AND "rank2" simultaneously. As such, a small fix will rectify that: {if $[board.id] == 9 && ($[current_user.rank.name] == "rank1" || $[current_user.rank.name] == "rank2")}
I've also added parenthesis. Now we're checking to see if the current user has "rank1" OR "rank2", taking that result AND then seeing if we're in board ID 9.
|
|
inherit
96289
0
May 17, 2020 9:37:00 GMT -8
elli
1,822
January 2007
ebbymac
|
Post by elli on May 18, 2019 11:15:27 GMT -8
Lynx You're right; I just did this quickly by only testing one rank.
|
|