Conditionally hide subscription form if already subscribed?

Kayla Johnson asked on September 17, 2018 16:42

We are adding a few content subscription widgets to our client's site. However, it is very confusing if the user is already subscribed, they still see the option to subscribe to it. Is there a way to change the Visibility of the widget to not show based on if the user is already subscribed to that one?

Correct Answer

Peter Mogilnitski answered on September 17, 2018 22:23

It should be something like this:

{%CurrentUser.ReferringObjects.Subscriptions.Filter(SubscriptionGatewayID == 1 && SubscriptionTemplateID == 123).Count|(identity)GlobalAdministrator%}

Basically you need to check if a record exists for given user and a given template (may be gateway if you have your custom one) in Notification_Subscription table. So if the count greater than 0 - hide the widget/form. I really dont know your setup I am just try to give you an idea :)

0 votesVote for this answer Unmark Correct answer

Recent Answers


Zach Perry answered on September 17, 2018 19:07

Is the user authenticated or is it public user?

0 votesVote for this answer Mark as a Correct answer

Kayla Johnson answered on September 18, 2018 23:14

It's for a logged in user.

I think this solution worked. It's hard to tell. I'm testing with a non-admin user and it seems to work okay. But the subscribe form doesn't hide/show immediately after subscribing/unsubscribing, unless I clear the cache.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.