Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Steve Grant_189967 Posted January 18, 2022 Posted January 18, 2022 One feature of my site is that there is limited free access to anybody who wishes to have it, but for unlimited access there is an annual subscription payable. For the "free" users (including guests), the tradeoff is that they are served adverts. I would like to ensure that the JavaScript file(s) that are loaded for the adverts are not even in the output HTML code for paid subscribers. For example: {{some template code to say "if user is not in Administrators, Moderators or Paid Subscribers groups, output this line"}} <script type="text/javascript" src="/some/path/to.js"></script> {{endif}} How would I achieve this? konon 1
Adriano Faria Posted January 18, 2022 Posted January 18, 2022 {{if !$member->inGroup( array( X, Y, Z ) )}} Show something {{endif}} SeNioR- and konon 1 1
Steve Grant_189967 Posted January 18, 2022 Author Posted January 18, 2022 @Adriano Faria Great, thanks - presumably the array is the ID for the group(s)?
Adriano Faria Posted January 18, 2022 Posted January 18, 2022 2 minutes ago, Steve Grant_189967 said: presumably the array is the ID for the group(s)? Yes. 👍
Adriano Faria Posted January 18, 2022 Posted January 18, 2022 You can use \IPS\Member::loggedIn() instead, If you don’t have the $member object. konon 1
Steve Grant_189967 Posted January 18, 2022 Author Posted January 18, 2022 Ah, so I'm getting an error saying there's an error in template includeJS which may be out of date, so I'm guessing $member isn't available there. But if I try isolating just the guests: <!-- Ad Testing --> {{if !\IPS\Member::loggedIn()}} <script type="text/javascript" src="script.js"></script> {{endif}} <!-- End Ad Testing --> So my logic is if the member is NOT logged in, allow the <script> tag to be included. That doesn't work - all I see is the comments wrapped around the if statement.
Adriano Faria Posted January 18, 2022 Posted January 18, 2022 No, mate. Replace only $member. You’re missing the group. {{if !\IPS\Member::loggedIn()->inGroup…}}
Steve Grant_189967 Posted January 18, 2022 Author Posted January 18, 2022 Gotcha, thanks 🤦♂️ {{if !\IPS\Member::loggedIn()->inGroup(array(4,6,7))}} <script type="text/javascript" src="script.js"></script> {{endif}} Now working 😎 SeNioR- 1
georgebkk Posted November 9, 2023 Posted November 9, 2023 On 1/18/2022 at 6:24 PM, Steve Grant_189967 said: Gotcha, thanks 🤦♂️ {{if !\IPS\Member::loggedIn()->inGroup(array(4,6,7))}} <script type="text/javascript" src="script.js"></script> {{endif}} Now working 😎 Is this still the correct way to load a script to guests only? Sorry to wake up an old thread, but i need to know. Thanks in advance {{if !\IPS\Member::loggedIn()->inGroup(array(4,6,7))}} <script type="text/javascript" src="script.js"></script> {{endif}}
Adriano Faria Posted November 9, 2023 Posted November 9, 2023 (edited) 13 minutes ago, thaivisa said: Is this still the correct way to load a script to guests only? if( \IPS\Member::loggedIn()->member_group_id == \IPS\Settings::i()->guest_group ) Edited November 9, 2023 by Adriano Faria
georgebkk Posted November 9, 2023 Posted November 9, 2023 Just now, Adriano Faria said: if( \IPS\Member::loggedIn()-member_group_id == \IPS\Settings::i()->guest_group )
Ryan Ashbrook Posted November 9, 2023 Posted November 9, 2023 Any of the following would likely work. {{if \IPS\Member::loggedIn()->inGroup( array( \IPS\Settings::i()->guest_group ) )}} {{if \IPS\Member::loggedIn()->member_group_id == \IPS\Settings::i()->guest_group}} {{if !\IPS\Member::loggedIn()->member_id}} Generally speaking, the third one is the most accepted way of determining if a user is a guest or not.
Recommended Posts