Conditionally render email editable regions

Nik Friedman TeBockhorst asked on September 24, 2015 19:18

I am looking for a way to conditionally render editable regions based on subscriber/contact information. (Specifically whether they have requested to receive certain topics.)

Here is the template I'm trying to create:

{%  if ( Contact.Topics.Contains("marketing") ) { %} 
$$Marketing_Content:500:250$$
{% } else { %} ​
$$Generic_Content:500:250$$
{% } #%}

When I create this template, none of the content in the editable regions is rendered.

If instead I include the macros within a single editable region when creating the template, the macros resolve properly, e.g.:

{%  if ( Contact.Topics.Contains("marketing") ) { %} 
People opted in for marketing will see this text.
{% } else { %} ​
This text will display for other people.
{% } #%}

Obviously, requiring editors to write macros in every email is a pretty poor user experience. Is there a way to build this personalization into the template instead?

(I did find this article that has a pretty kludgy way to make this happen. I'm hoping to create a more streamlined experience.)

Recent Answers


Maarten van den Hooven answered on September 24, 2015 21:48

Sorry I don't see another solution then the one described in that article, hopefully another Kentico expert will known something or has some experience with this challenge.

I will also think about and ask around, if I have a new inside I will directly let you known.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on September 29, 2015 13:46

Hi,
This scenario is currently not supported. But our product manager liked that idea and it is on the list of features for next Kentico versions.

0 votesVote for this answer Mark as a Correct answer

Pavel Jiřík answered on October 23, 2015 15:09

Hi, there is actually a way how to achieve this. You can use anonymous macro signature "@":

{%  if ( Contact.Topics.Contains("marketing") ) { %}
$$Marketing_Content:500:250$$
{% } else { %}
$$Generic_Content:500:250$$
{% } @%}

By using "@" at the end of macro, you disable macro security checks and the macro acts like it would be signed by a public user. This basically means that its content can be changed without any restrictions. On the other hand, it has limited access to resources.

However, the important thing is that system checks the context of each anonymous macro.

So, if you insert such a macro into an email template inside of email marketing module, the system expects you to have enough permissions to be actually able to insert the macro there (e.g. valid password, permissions for editing email marketing module, etc.). Because of that it allows this macro access to current context - in this case, access to contacts or subscribers.

0 votesVote for this answer Mark as a Correct answer

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