Sitecore mail template with rich text field

284 views Asked by At

Im trying to create a custom mail system in Sitecore. For this i want to be able to use razor code inside my mail item in the Sitecore backend. This code will be place inside the body field which will be a rich text. Currently I'm working on a Sitecore 8 instance.

Now here is my problem. Whenever I put a piece of code like:

@for (var i = 0; i > @model.persons.count;  i++){

the rich text fields changes the line of code to:

@for (var i = 0; i < @model.documents.count;  i++){

or even worse..

Does anybody have an idea why this is happening and what I can do to prevent this. Cause now it changes every time somebody wants to make a change to the email message and it is quite annoying.

Thanks in advance.

2

There are 2 answers

0
Ian Graham On

In this scenario I would use some kind of token in the rich text email message field. E.g $persondata$.

Then I would use a pipeline processor to replace the tokens in the email with the real data. This keeps it nice and clean and is easier for editors.

0
RvanDalen On

I've used this approach as well, using the RazorEngine to parse the richtext with a dynamic model, still use it actually. But I try to refrain from doing anything other than writing properties because of the problems you mentioned + customers tend to mess it up anyway because they lack knowledge about razor syntax and theres no intellisense to help them.

I would opt to have another rich text field for a single document.

<li>@model.documentName - @model.documentPrice</li>

And iterate/parse the documents before you stuff it into a model.parseddocuments property. That way you only need to apply

<ul>@model.parseddocuments</ul>