Alternative text if no membership allocated

Alan Isaacson asked on October 27, 2016 15:04

I currently have a transformation that checks a field has content and then delivers the content via the code {% DisplayDiseaseContentField("Etiology", DiseasePathogenesisEtiology) %} However I would now like to make the content visible to certain memberships only and if they are not a member of that group to have a login or register option.

EG. If membership = CanisSubscription and {% DisplayDiseaseContentField("Etiology", DiseasePathogenesisEtiology) %} else (Login or register)

Each transformation may contain a group of these so it could be

If currentuser.hasmembership == Canis subscription

{% DisplayDiseaseContentField("Etiology", DiseasePathogenesisEtiology) %}
{% DisplayDiseaseContentField("Predisposing factors", DiseasePathogenesisPredisposingFactors) %}
{% DisplayDiseaseContentField("Pathophysiology", DiseasePathogenesisPathophysiology) %}
{% DisplayDiseaseContentField("Timecourse", DiseasePathogenesisTimecourse) %}
{% DisplayDiseaseContentField("Epidemiology", DiseasePathogenesisEpidemiology) %}

else 

<p>Please login or register</p>

Any ideas on the best syntax to do this?

Correct Answer

Jan Hermann answered on October 27, 2016 15:28

Try this one:

{%
if (MembershipContext.AuthenticatedUser.HasMembership("someMembership")) {
%}
html/macros
{%
}
else {
%}
html/macros
{% 
}
%}
0 votesVote for this answer Unmark Correct answer

Recent Answers


Alan Isaacson answered on November 9, 2016 18:21

Very good answer, is it possible to change the line if (MembershipContext.AuthenticatedUser.HasMembership("someMembership"))

so if they do not have the specified membership.

Also so "someMembership" could be made from half text and a fieldname such as "some +CurrentDocument.Parent"

As this way it can cover multiple memberships as they all have similiar paths.

0 votesVote for this answer Mark as a Correct answer

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