Change the email content when a user is approved by role

toru sato asked on June 26, 2020 08:18

Hi An administrator's approval is required at the time of user registration, and an email is sent after approval. I want to change the content of the email at that time with the role of the registered user.

Changed the Membership-Registration approved template as follows.

{% if (CurrentUser.IsInRole("SampleRole")=="True") {%}
<p>
  IsInRole
</p>
{% }else{ %}
<p>
  NotIsInRole
</p>    
{% } #%}

When the user of SampleRole is approved, an email is sent with the following contents.

<p> NotIsInRole </p>

The tag is output as it is, and it seems that the role cannot be determined. Those who understand the cause Can you give me any advice?

Correct Answer

David te Kloese answered on July 2, 2020 12:19

The encoding does the trick on the rendering tags. Secondly you should compare to an actual Bool value! You're comparing to a string:

macro in email

The following should do the trick:

{% if (User.IsInRole("ChatSupportEngineers")==true) {%}
<p>  IsInRole </p>
{% }else{ %}
<p> NotIsInRole </p>       
{%}|(encode)false#%}
0 votesVote for this answer Unmark Correct answer

Recent Answers


Sultan Ahmed answered on June 26, 2020 11:36

What is the issue? Your syntax looks correct. Did you try this? managing-email-templates

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on June 26, 2020 14:01

Hi,

I understand the confusion, but currentuser is in this case probably NOT your newly registered user.

This task is probably triggered by a random website visit or an administrator. If you change your macro to CurrentUser.UserName you'll probably won't see the new username.

However in the template you see what is available in the current context and it seems you have access to a USER object. Can you try using that with the same logic:

macro

0 votesVote for this answer Mark as a Correct answer

toru sato answered on June 29, 2020 03:36

Hi 

Thank you for both answers

I changed to use user.isinrole, but the judgment was still false. Also, the p tag is not processed as an HTML tag and is output as it is.

0 votesVote for this answer Mark as a Correct answer

Sultan Ahmed answered on June 29, 2020 09:08 (last edited on June 29, 2020 09:23)

For Judgment was false, one question is this user already created and has role? Did you try printing and check what is the role user is in? I guess the role is being checked before the role is actually applied. Please cross check once.

And for Html part, Did you try to set encode to false when you end if statement? Something like this:

{% if (CurrentUser.IsInRole("SampleRole")=="True") {%}
<p>
  IsInRole
</p>
{% }else{ %}
<p>
  NotIsInRole
</p>       
{%}|(encode)false|(identity)GlobalAdministrator%}
0 votesVote for this answer Mark as a Correct answer

toru sato answered on July 2, 2020 10:11

Hi Sultan,

Thanks for the answer. Yes, I have confirmed that roles are set up for users at the Approve stage. Also, I mentioned the following but the email sent did not change.

{%}|(encode)false|(identity)GlobalAdministrator%}
0 votesVote for this answer Mark as a Correct answer

toru sato answered on July 7, 2020 09:14

Hi David

Thanks for the answer! We're done!

Thanks so much to everyone who responded. It was helpful.

0 votesVote for this answer Mark as a Correct answer

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