Multiple Switches on one template event

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 4282
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James
Contact:

Multiple Switches on one template event

Post by HiFiKabin »

I have created 3 working switches, but can not get them to work correctly in the combinations I need.

The switches are:-

NEWSSCROLL_ACTIVATED
NEWSSCROLL_INDEX
NEWSSCROLL_MEMBER

and what I have in the event/html is:-

Code: Select all

<!-- IF S_NEWSSCROLL_ACTIVATED -->
    <!-- IF S_NEWSSCROLL_INDEX and S_INDEX-->
        <!-- IF S_NEWSSCROLL_MEMBER and S_USER_LOGGED_IN -->
HTML CODE
        <!-- ENDIF -->
    <!-- ENDIF -->
<!-- ENDIF -->
But they are only displaying the contents with all set to 'on'

With NEWSSCROLL_ACTIVATED I am looking for is the HTML:-

Showing on every page

or

Showing on index page

or

Showing on every page only to members

or

Showing on index page only to members

dependant on the status of the other 2 switches

I have done a search, but with no luck. Am I asking the impossible?

User avatar
david63
Registered User
Posts: 17050
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Multiple Switches on one template event

Post by david63 »

Just taking a wild stab at it - but try

Code: Select all

<!-- IF S_NEWSSCROLL_ACTIVATED -->
    <!-- IF S_NEWSSCROLL_INDEX and S_INDEX or S_NEWSSCROLL_MEMBER and S_USER_LOGGED_IN -->
HTML CODE
        <!-- ENDIF -->
<!-- ENDIF -->
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 4282
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James
Contact:

Re: Multiple Switches on one template event

Post by HiFiKabin »

Thanks but no joy I'm afraid David. Members only is working. Index only is working, but both together allows logged out viewing. *scratches head*

Odd

User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Multiple Switches on one template event

Post by javiexin »

How about the following? Untested...

Code: Select all

<!-- IF S_NEWSSCROLL_ACTIVATED -->
	<!-- IF S_NEWSSCROLL_INDEX and S_INDEX or not S_NEWSCROLL_INDEX -->
		<!-- IF S_NEWSSCROLL_MEMBER and S_USER_LOGGED_IN or not S_NEWSCROLL_MEMBER -->
HTML
		<!-- ENDIF -->
	<!-- ENDIF -->
<!-- ENDIF -->
-javiexin

User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Multiple Switches on one template event

Post by javiexin »

Really, you could simplify a bit. Untested as well...

Code: Select all

<!-- IF S_NEWSSCROLL_ACTIVATED -->
	<!-- IF S_INDEX or not S_NEWSCROLL_INDEX -->
		<!-- IF S_USER_LOGGED_IN or not S_NEWSCROLL_MEMBER -->
HTML
		<!-- ENDIF -->
	<!-- ENDIF -->
<!-- ENDIF -->
Easier to understand as

Code: Select all

<!-- IF S_NEWSSCROLL_ACTIVATED -->
	<!-- IF S_INDEX or S_NEWSCROLL_EVERYWHERE -->
		<!-- IF S_USER_LOGGED_IN or S_NEWSCROLL_GUESTS -->
HTML
		<!-- ENDIF -->
	<!-- ENDIF -->
<!-- ENDIF -->
-javiexin

User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 4282
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James
Contact:

Re: Multiple Switches on one template event

Post by HiFiKabin »

Nope, Sorry Javier but once enabled that displays the html at any switch position

User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Multiple Switches on one template event

Post by canonknipser »

I'm afraid you have to do more coding ;)
You have 5 switches at all ;)

1 = S_NEWSSCROLL_ACTIVATED
2 = S_NEWSSCROLL_INDEX
3 = S_NEWSSCROLL_MEMBER
4 = S_USER_LOGGED_IN
5 = S_INDEX
Do you have a decision table?
Depending on your 5 conditions you can have 2^5 = 32 rules

So, as this would be very long and complicated in template code, wouldn't it be better to check in your PHP-Code, if your html should show up? Then you can break it down to one template switch
So check if (not sure if that's all)
a)Member only and Member logged in and Show only on Index and is-index
b) Member only and Member logged in and NOT Show only on Index
c) NOT Member only and Show only on Index and is-index
d) NOT Member only and NOT Show only on Index

z) if Activated and any rule above is true, Set show_html to true ;)
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB

User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Multiple Switches on one template event

Post by javiexin »

canonknipser wrote:I'm afraid you have to do more coding ;)
You have 5 switches at all ;)

1 = S_NEWSSCROLL_ACTIVATED
2 = S_NEWSSCROLL_INDEX
3 = S_NEWSSCROLL_MEMBER
4 = S_USER_LOGGED_IN
5 = S_INDEX
Do you have a decision table?
Depending on your 5 conditions you can have 2^5 = 32 rules

So, as this would be very long and complicated in template code, wouldn't it be better to check in your PHP-Code, if your html should show up? Then you can break it down to one template switch
So check if (not sure if that's all)
a)Member only and Member logged in and Show only on Index and is-index
b) Member only and Member logged in and NOT Show only on Index
c) NOT Member only and Show only on Index and is-index
d) NOT Member only and NOT Show only on Index

z) if Activated and any rule above is true, Set show_html to true ;)
That was almost exactly my reasoning:
Starting from your bottom:
1) Only display if Activated
2) If you are On index, or anywhere else without Show only on index, then
3) If you are Logged In, or guest without Show only to members
Show it...
HiFiKabin wrote:Nope, Sorry Javier but once enabled that displays the html at any switch position
Sure? Shouldn't... Check the edits and the switch values, maybe not getting what you expect... Before your HTML code, put some kind of dump trace

Code: Select all

<pre>S_NEWSSCROLL_ACTIVATED&nbsp;&bull;{S_NEWSSCROLL_ACTIVATED}&bull;<br/>
S_NEWSSCROLL_INDEX&nbsp;&bull;{S_NEWSSCROLL_INDEX}&bull;<br/>
S_NEWSSCROLL_MEMBER&nbsp;&bull;{S_NEWSSCROLL_MEMBER}&bull;<br/>
S_USER_LOGGED_IN&nbsp;&bull;{S_USER_LOGGED_IN}&bull;<br/>
S_INDEX&nbsp;&bull;{S_INDEX}&bull;</pre>
It should work mostly as posted (of course, there might be typos, or variables not set properly...)
-javiexin

User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 4282
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James
Contact:

Re: Multiple Switches on one template event

Post by HiFiKabin »

Javier. I have checked with your code and all switches work correctly.

Guess I'll have another think about it.

EDIT Actually there are far less combinations than that, S_INDEX and S_USER_LOGGED_IN are existing template switches. S_NEWSSCROLL_INDEX is only used with S_INDEX and S_NEWSSCROLL_MEMBER is only used with S_USER_LOGGED_IN

S_NEWSSCROLL_ACTIVATED is an on/off switch for the whole extension.

So there are only 4 states of switch combinations:-

Code: Select all

index	off	member	off
index	on	 member	off
index	on	 member	on
index	off	member	on
The following (although messy) works as intended

Code: Select all

<!-- IF S_NEWSSCROLL_ACTIVATED and not S_NEWSSCROLL_INDEX and not S_NEWSSCROLL_MEMBER -->
HTML
<!-- ENDIF -->
<!-- IF S_NEWSSCROLL_ACTIVATED and S_NEWSSCROLL_INDEX and S_INDEX and not S_NEWSSCROLL_MEMBER -->
HTML
<!-- ENDIF -->
<!-- IF S_NEWSSCROLL_ACTIVATED and S_NEWSSCROLL_INDEX and S_INDEX and S_NEWSSCROLL_MEMBER and S_USER_LOGGED_IN -->
HTML
<!-- ENDIF -->
<!-- IF S_NEWSSCROLL_ACTIVATED and S_NEWSSCROLL_MEMBER and S_USER_LOGGED_IN and not 
HTML
<!-- ENDIF -->
There must be a better way (but I haven't found it yet :roll: )

User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Multiple Switches on one template event

Post by javiexin »

Step by step.
One: <!-- IF S_NEWSSCROLL_ACTIVATED --> could be moved out of all switches to a separate IF surrounding everything else, as the global switch it is.
Two: S_NEWSSCROLL_INDEX and S_INDEX may be simpliefied as S_INDEX as in case S_NEWSSCROLL_INDEX is false, it should display anyway on index
Three: S_NEWSSCROLL_MEMBER and S_USER_LOGGED_IN may be simplified as S_USER_LOGGED_IN for similar reasons as above, if S_NEWSSCROLL_MEMBER is false, it should display to registered anyway

With these changes, you would have:

Code: Select all

<!-- IF S_NEWSSCROLL_ACTIVATED -->
	<!-- IF not S_NEWSSCROLL_INDEX and not S_NEWSSCROLL_MEMBER -->
		HTML
	<!-- ELSEIF not S_NEWSSCROLL_INDEX and S_USER_LOGGED_IN -->
		HTML
	<!-- ELSEIF S_INDEX and not S_NEWSSCROLL_MEMBER -->
		HTML
	<!-- ELSEIF S_INDEX and S_USER_LOGGED_IN -->
		HTML
	<!-- ENDIF -->
<!-- ENDIF -->
Note the change from IF to ELSEIF, to avoid duplicates in the code due to the above simplification, for clarity.

Now, let's do some logic grouping:

Code: Select all

<!-- IF S_NEWSSCROLL_ACTIVATED -->
	<!-- IF not S_NEWSSCROLL_INDEX and ( not S_NEWSSCROLL_MEMBER or S_USER_LOGGED_IN ) -->
		HTML
	<!-- ELSEIF S_INDEX and ( not S_NEWSSCROLL_MEMBER or S_USER_LOGGED_IN ) -->
		HTML
	<!-- ENDIF -->
<!-- ENDIF -->
Further logic grouping gives:

Code: Select all

<!-- IF S_NEWSSCROLL_ACTIVATED -->
	<!-- IF ( not S_NEWSSCROLL_INDEX or S_INDEX ) and ( not S_NEWSSCROLL_MEMBER or S_USER_LOGGED_IN ) -->
		HTML
	<!-- ENDIF -->
<!-- ENDIF -->
To make it clearer:

Code: Select all

<!-- IF S_NEWSSCROLL_ACTIVATED -->
	<!-- IF not S_NEWSSCROLL_INDEX or S_INDEX -->
		<!-- IF  not S_NEWSSCROLL_MEMBER or S_USER_LOGGED_IN -->
			HTML
		<!-- ENDIF -->
	<!-- ENDIF -->
<!-- ENDIF -->
Surprise surprise, the same code I proposed at the beginning...

So, if your code works, but this one doesn't, there must be something in the syntax or typo...
Check it out... This way, the code is not so messy.

Regards,
-javiexin

User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 4282
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James
Contact:

Re: Multiple Switches on one template event

Post by HiFiKabin »

javiexin wrote:<snip>

To make it clearer:

Code: Select all

<!-- IF S_NEWSSCROLL_ACTIVATED -->
	<!-- IF not S_NEWSSCROLL_INDEX or S_INDEX -->
		<!-- IF  not S_NEWSSCROLL_MEMBER or S_USER_LOGGED_IN -->
			HTML
		<!-- ENDIF -->
	<!-- ENDIF -->
<!-- ENDIF -->
Surprise surprise, the same code I proposed at the beginning...

So, if your code works, but this one doesn't, there must be something in the syntax or typo...
Check it out... This way, the code is not so messy.

Regards,
-javiexin
*slaps forehead* well bugger me, its working now *scratches head, removes splinter*

I checked and double checked the edits and syntax earlier, and it wasn't working, now it it. I blame the wicked computer elves :roll:

Thanks Javier, Having been at this most of the day, just getting more and more frustrated. You have saved me pulling out what little remaining hair I have.

User avatar
3Di
Former Team Member
Posts: 14720
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Multiple Switches on one template event

Post by 3Di »

Yeah, he saved my little remaining ones as well but for another issue. ;)
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
:studio_microphone: Premium extensions @ The Studio

User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Multiple Switches on one template event

Post by javiexin »

Please, keep all your hair, by all means! :lol: :lol:

Post Reply

Return to “Extension Writers Discussion”