serenity-is / Serenity

Business Apps Made Simple with Asp.Net Core MVC / TypeScript
https://serenity.is
MIT License
2.59k stars 794 forks source link

Customize .cshtml (Email template) #4684

Closed ga5tan closed 4 years ago

ga5tan commented 4 years ago

Hi

so I am using Serenity's way, to send out email:

`var emailModel = new TransferRegistrationEmailModel(); emailModel.QA = user.DisplayName; emailModel.Code = TransferCode; emailModel.Url = URL;

        var emailSubject = Texts.Site.UserDialog.InviteNonQAEmailSubject;
        var emailBody = TemplateHelper.RenderTemplate(
            MVC.Views.Users.Users_.TransferRegistrationEmail, emailModel);

        Common.EmailHelper.Send(emailSubject, emailBody, request.Entity.Email);`

but I would need to be able for users to modify cshtml template. Did anybody tried that? I would most likely want ot have cshtml is DB table. is it possible to use from table, rather than from field?

RKayCH commented 4 years ago

Mhn, I wouldn't put a whole cshtml into the db. Not only because it's not MVC anymore then. The cshtml content (the actualy file's content), is mostly static for longer periods - you design/develop - go live - until a rework/redesign - you usually dont change a lot. And most of the changes happening then are CSS-based, or is your requirements profile different?

Some ideas:

How I do the email stuff:

If you want, feel free to message me to discuss it - always eager to see what solutions others find/use .

ga5tan commented 4 years ago

@RKayCH thx for elaborate post! Yeah, I thought about just storing parts of the template in DB or even better in Serenity scripts, so that I can get the power of multilanguage and translations...

Letting users(Admins) to edit file would also be nice...I just thought editing it in DB would be more "elegant" aproach You are right it wont be happening often, but still would be better than have to release new version because of this...Or reuploading individual files

RKayCH commented 4 years ago

I see you points, in the end, the elegance comes from the editing options - not the source, as nobody would see anything which is hidden "behind the curtains".

The actual data (text - in regards to the translations you mentioned) - I would keep on the DB. Text (which is DATA) - if strictly following MVC - should not be part of the template cshtml itself, but depending on your project/size, it could be a bit overkill to do it that strict. In th end, it's mostly a question of cost-effectiveness analysis and "internal guidelines" on the team.

Anyway, let me know how it's going and if you have further questions. Cheerio

volkanceylan commented 4 years ago

You may use scriban/markdown for email templates, and could store them in db as well.