doxakis / MailBody

Create transactional email with a fluent interface (.net)

Home Page:https://doxakis.github.io/MailBody/

Repository from Github https://github.comdoxakis/MailBodyRepository from Github https://github.comdoxakis/MailBody

Pass attributes to Paragraph with Block content

jjavierdguezas opened this issue · comments

Hi, first thanks for this awesome tool

--

This is my issue:

I have made changes to the Paragraph template so that it can accept fontSize and color attributes, similar to the example provided in the README.md file):

template.Paragraph(m => $"<p style='font-family: sans-serif; font-size: {(m.IsProperty(() => m.Attributes.fontSize) ? m.Attributes.fontSize : "14px")}; font-weight: normal; margin: 0; Margin-bottom: 15px;{(m.IsProperty(() => m.Attributes.color) ? $" color: {m.Attributes.color};" : string.Empty)}'>{m.Content}</p>");

Then I have a paragraph with a Block inside

 var body = MailBody
             .CreateBody()
             ....
             .Paragraph(MailBody.CreateBlock().Text("Text...").LineBreak().Link(url), new { color = "#7F88A1", fontSize = "12px" });

but Attributes is null in Paragraph func

Reviewing MailBody codebase I found this:

public MailBlockFluent Paragraph(MailBlockFluent block, dynamic attributes = null)
{
_commands.Add(() =>
{
// Propagate template.
block._template = this._template;
var element = new ContentElement
{
Content = block.ToString()
};
return _template.Paragraph()(element);
});
return this;
}

should MailBody pass the attributes argument to the ContentElement ?

PS: I can submit the PR if needed

Hi, thank you! :)

--

Yes, you are totally right and I fixed it.
I pushed a new version on Nuget (1.1.5)