Developer forum

Forum » Development » How to get Recipient ID in razor

How to get Recipient ID in razor

Kasper Laursen
Reply

Hi there,

I've been searching far and wide for this and have come up short. Isn't there any way to get the ID of the user/recipient of an email inside a razor template?

I am aware of the existance of email placeholder tags where i can use EmailMessaging:Recipient.ID/Key, but this doesn't give me the id of the user to use immediately. Can't I do something like GetValue("EmailMessaging:Recipient.ID") or similar?

Any other way?

Currently, I'm leaning towards using the placeholder tag and then fetching that data in a BeforeEmailSend trigger. This seems excessively complex for what I expect is quite simple.

Regards,
Kasper


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply
This post has been marked as an answer

Hi Kasper,

 

You should be able to get user data using {{EmailMessaging:Recipient.Name}} or {{Email:User.Name}}. The syntax for "tags" is different for emails.

Check all you can do here https://doc.dynamicweb.com/documentation-9/marketing/email-marketing/placeholder-tags

 

For this to work you need to be sure the checkbox "Render content for each recipient" in the advanced tab is enabled. You'll get a null object if it's not.

 

Ultimately you can also do this:

var user = Pageview.Context.GetValue("User") as User;

Then using the API you can get anything from that user. 

 

Hope this helps,

Nuno Aguiar

Votes for this answer: 1
 
Kasper Laursen
Reply

Hi Nuno,

Perfect amswer. Thank you.

The second part is what I am interested in.

Regards,
Kasper

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Thank you and, you are welcome

 

You must be logged in to post in the forum