Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted January 18, 20223 yr 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?
January 18, 20223 yr Author @Adriano Faria Great, thanks - presumably the array is the ID for the group(s)?
January 18, 20223 yr 2 minutes ago, Steve Grant_189967 said: presumably the array is the ID for the group(s)? Yes. 👍
January 18, 20223 yr You can use \IPS\Member::loggedIn() instead, If you don’t have the $member object.
January 18, 20223 yr Author 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.
January 18, 20223 yr No, mate. Replace only $member. You’re missing the group. {{if !\IPS\Member::loggedIn()->inGroup…}}
January 18, 20223 yr Author Gotcha, thanks 🤦♂️ {{if !\IPS\Member::loggedIn()->inGroup(array(4,6,7))}} <script type="text/javascript" src="script.js"></script> {{endif}} Now working 😎
November 9, 20231 yr 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}}
November 9, 20231 yr 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, 20231 yr by Adriano Faria
November 9, 20231 yr Just now, Adriano Faria said: if( \IPS\Member::loggedIn()-member_group_id == \IPS\Settings::i()->guest_group )
November 9, 20231 yr 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.