inherit
217158
0
Oct 24, 2020 18:36:20 GMT -8
Ginger
53
December 2014
gingerfrost2
|
Post by Ginger on Sept 29, 2020 15:47:21 GMT -8
{if $[thread.id] == 5}
I managed to do it once, then accidentally deleted the code... Now incapable of replicating it. So basically, how do I list multiple thread ids to get a single if loop repeating same process.
That way I only need 1 loop versus a bunch of {else} {if $[thread.id] == 9} loops inside the first loop.
|
|
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 29, 2020 16:22:18 GMT -8
{if $[thread.id] == 5} I managed to do it once, then accidentally deleted the code... Now incapable of replicating it. So basically, how do I list multiple thread ids to get a single if loop repeating same process. That way I only need 1 loop versus a bunch of {else} {if $[thread.id] == 9} loops inside the first loop. || is "or". so you'd do {if $[thread.id] ==9 || $[thread.id] == 2} etc.
|
|
inherit
217158
0
Oct 24, 2020 18:36:20 GMT -8
Ginger
53
December 2014
gingerfrost2
|
Post by Ginger on Sept 29, 2020 16:37:45 GMT -8
Thank you <3 I had to add a space between | | to get it to work, THANK YOU.
|
|
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 29, 2020 16:46:17 GMT -8
Thank you <3 I had to add a space between | | to get it to work, THANK YOU. Umm you shouldn't have had to do that, for what it's worth. A || with a space would be incorrect syntax, as "or" is specifically two vertical pipes, in the same way "and" is two ampersands (&&). Would you mind posting your template here? If it's not working with || as it's meant to be written, that points to incorrect coding elsewhere.
|
|
inherit
217158
0
Oct 24, 2020 18:36:20 GMT -8
Ginger
53
December 2014
gingerfrost2
|
Post by Ginger on Sept 29, 2020 16:57:49 GMT -8
It worked without a space, I maaay been staring at code for too long.
-was planning on editing post before you replied-
here's the code though,
{if $[thread.id] == 5 || $[thread.id] == 160} {else} $[thread.created_by.avatar_quote]{/if}
|
|
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 29, 2020 17:11:51 GMT -8
It worked without a space, I maaay been staring at code for too long. -was planning on editing post before you replied- here's the code though, {if $[thread.id] == 5 || $[thread.id] == 160} {else} $[thread.created_by.avatar_quote]{/if} This doesn't look like the right syntax, unfortunately! Would I be correct in guessing that your intention is that for threads 5 and 160 you want to show the 'thread created by avatar' in quote size, but not for any other thread? If not, what is your goal here?
|
|
inherit
217158
0
Oct 24, 2020 18:36:20 GMT -8
Ginger
53
December 2014
gingerfrost2
|
Post by Ginger on Sept 29, 2020 18:17:30 GMT -8
reversed, I want it not to show and other threads do show.
|
|
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 29, 2020 19:02:12 GMT -8
reversed, I want it not to show and other threads do show. Ah I see, that's why you left it blank. What I would do instead of having an empty section to use != instead of == for "is not" that way it reads {if $[thread.id] != 5 && $[thread.id] != 160} $[thread.created_by.avatar_quote] {/if} and you wont have an empty declaration.
|
|
inherit
252032
0
Apr 26, 2024 23:51:41 GMT -8
Retread
Tribbial Pursuit.
5,017
January 2018
retread
|
Post by Retread on Sept 29, 2020 19:02:50 GMT -8
reversed, I want it not to show and other threads do show. Hi Ginger What you posted will do just that. {if $[thread.id] == 5 || $[thread.id] == 160} {else} $[thread.created_by.avatar_quote]{/if} What you are literally saying is ... If the thread ID is 5, OR the thread ID is 160, Then: Do nothing ( there is nothing between the {if} and the {else} )Else: Display the avatar
There is a very slightly shorter way to accomplish this. {if $[thread.id] != 5 && $[thread.id] != 16} $[thread.created_by.avatar_quote]{/if} This means ... If the thread ID is not 5, AND the thread ID is not 160, Then: Display the avatar. Which one should you use? Potayto, potahto. EDIT: Ninja'd by Kami
|
|
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 29, 2020 19:07:21 GMT -8
For whatever it's worth i recommend retread's second method because it is the correct way of writing this and i have edited my post accordingly You may achieve the same result but you're creating extra steps to go through instead of simply excluding the two threads you don't want to use. A lot of programming is semantics based, and best practice is to have as little unnecessary content as possible. If you can write something more cleanly in less lines it's better.
|
|
inherit
140147
0
Nov 19, 2024 5:07:22 GMT -8
Nscalerr
Throw me to the wolves and I'll return leading the pack!
3,043
May 2009
nscalerr
|
Post by Nscalerr on Sept 29, 2020 22:21:18 GMT -8
Only thing Retread, I believe this means it has to be thread id 5 AND thread id 160 at the same time, which is of course not possible! What Kami came up with is far better in this situation. {if $[thread.id] != 5 && $[thread.id] != 160} {if $[thread.id] != 5 || $[thread.id] != 160}
|
|
inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,849
January 2015
msg
|
Post by Lynx on Sept 29, 2020 22:49:35 GMT -8
Only thing Retread, I believe this means it has to be thread id 5 AND thread id 160 at the same time, which is of course not possible! What Kami came up with is far better in this situation. {if $[thread.id] != 5 && $[thread.id] != 160} {if $[thread.id] != 5 || $[thread.id] != 160} If you're checking values NOT EQUAL, then you'll want to go with AND (&&). Using OR in that case would always result in true using the !=. IF it were coded as this: {if $[thread.id] != 5 || $[thread.id] != 160} // code here {/if}
since the thread ID can't be 5 and 160 at the same time, one of conditions those will always result in true - since it only takes ONE of the conditionals to be true to make the OR True.. If the thread ID is 5, then it's not 160 = true. If the thread ID is 160, then it's not 5 = true. That's why you want AND, since you don't want the thread ID to be either of those - and ALL conditionals must be true for the AND to return a True.
|
|
inherit
140147
0
Nov 19, 2024 5:07:22 GMT -8
Nscalerr
Throw me to the wolves and I'll return leading the pack!
3,043
May 2009
nscalerr
|
Post by Nscalerr on Sept 29, 2020 22:58:32 GMT -8
Thanks Lynx, very helpful.
|
|
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 30, 2020 5:13:19 GMT -8
Yep MSG is correct, this is why I shouldn't try to do templates right before bed 😂 I've edited my post accordingly
|
|
inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,849
January 2015
msg
|
Post by Lynx on Sept 30, 2020 11:00:08 GMT -8
Yep MSG is correct, this is why I shouldn't try to do templates right before bed 😂 I've edited my post accordingly Heh, been there and done that working on some of my plugins. Yep, just before bedtime definitely not the time to work on them.
|
|