Steve Grant_189967 Posted January 18 Share Posted January 18 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? Link to comment Share on other sites More sharing options...
Adriano Faria Posted January 18 Share Posted January 18 {{if !$member->inGroup( array( X, Y, Z ) )}} Show something {{endif}} SeNioR- 1 Link to comment Share on other sites More sharing options...
Steve Grant_189967 Posted January 18 Author Share Posted January 18 @Adriano Faria Great, thanks - presumably the array is the ID for the group(s)? Link to comment Share on other sites More sharing options...
Adriano Faria Posted January 18 Share Posted January 18 2 minutes ago, Steve Grant_189967 said: presumably the array is the ID for the group(s)? Yes. 👍 Link to comment Share on other sites More sharing options...
Steve Grant_189967 Posted January 18 Author Share Posted January 18 Thank you! Link to comment Share on other sites More sharing options...
Adriano Faria Posted January 18 Share Posted January 18 You can use \IPS\Member::loggedIn() instead, If you don’t have the $member object. Link to comment Share on other sites More sharing options...
Steve Grant_189967 Posted January 18 Author Share Posted January 18 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. Link to comment Share on other sites More sharing options...
Adriano Faria Posted January 18 Share Posted January 18 No, mate. Replace only $member. You’re missing the group. {{if !\IPS\Member::loggedIn()->inGroup…}} Link to comment Share on other sites More sharing options...
Steve Grant_189967 Posted January 18 Author Share Posted January 18 Gotcha, thanks 🤦♂️ {{if !\IPS\Member::loggedIn()->inGroup(array(4,6,7))}} <script type="text/javascript" src="script.js"></script> {{endif}} Now working 😎 SeNioR- 1 Link to comment Share on other sites More sharing options...
Recommended Posts