Adding mulitple memberships to a query as a macro

Alan Isaacson asked on November 11, 2016 13:40

Jan very helpfully supplied a macro for me that allows content to change depending on a membership within a transformation.

{%
if (MembershipContext.AuthenticatedUser.HasMembership("someMembership")) {
%}
html/macros
{%
}
else {
%}
html/macros
{% 
}
%}

I would like to be able to set it so that I can list multiple memberships such as * SilverMonth * GoldMonth * PlatinumMonth * SilverAnnual * GoldAnnual * PlatinumAnnual
That way the macro could specify

(MembershipContext.AuthenticatedUser.HasMembership("{currentdocument.parent.parent}Annual,{currentdocument.parent.parent}Month,")) The currentdocument.parent.parent would always be either silver, gold or platinum.

Correct Answer

Jim Spillane answered on November 11, 2016 15:24

Alan - You can try something like this to format it like Anton suggested:

{% 
prefix = "gold";
MembershipCodeNames = prefix + "monthly;" + prefix + "annual;" + prefix + "quarterly";
if (MembershipContext.AuthenticatedUser.HasMembership(MembershipCodeNames) ) {
%}
true html/macros
{% } else { %}
false html/macros
{% } |(identity)GlobalAdministrator%}

The prefix can be set to a variable, rather than a string like:

prefix = currentdocument.parent.DocumentName

0 votesVote for this answer Unmark Correct answer

Recent Answers


Anton Grekhovodov answered on November 11, 2016 14:07

Hi Alan,

I think you can pass all necessary values separated by semicolon:

Image Text

1 votesVote for this answer Mark as a Correct answer

Alan Isaacson answered on November 11, 2016 14:15

Thanks Anton, but could I use a wildcard so that part of the membership is based upon the document path eg: the suffix of the membership name is a a variable such as prefix="currentdocument.parent.parent" (This would then always result in Gold, Silver, Platinum, Onyx etc and the second part I could type as Month, Annual, Quarterly etc so it would then give a result of prefixMonth;prefixannual;prefixQuarterly

0 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on November 11, 2016 21:20

Alan,

Jim gave you a correct answer.

Also, instead of string concatenation, you can use string formatting:

MembershipCodeNames = FormatString("{0}month;{0}annual;{0}quarterly", prefix);
0 votesVote for this answer Mark as a Correct answer

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