Jump to content

Limit JS script loading to specific usergroups

Recommended Posts

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>

How would I achieve this?

Link to comment
Share on other sites

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>
<!-- 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


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...