I am using the Razor engine https://github.com/Antaris/RazorEngine to parse the body of my email templates. Is it possible to define a layout and include other .cshtml files? for example a common header and a footer.
I am using the Razor engine https://github.com/Antaris/RazorEngine to parse the body of my email
Share
I got common templates and a layout working, with the help of these two posts:
RazorEngine string layouts and sections?
http://blogs.msdn.com/b/hongyes/archive/2012/03/12/using-razor-template-engine-in-web-api-self-host-application.aspx
This is my solution:
Solution 1:
Layout
Used by setting _Layout
Footer
Layout.cshtml
TemplateBaseExtensions
Extend TemplateBase with a RenderPart Method
Razor Config
Set BaseTemplateType to your TemplateBaseExtensions class
Edit Solution 2:
If you are using a TemplateResolver. RenderPart isn’t needed use the @Include instead
Footer
Resolver
Config
Update by The Muffin Man
Specify a template and render a string
Also I, along with others at this link https://github.com/Antaris/RazorEngine/issues/61 had issues with using
_LayoutwhereasLayoutworked.‘_Layout’ is the old syntax. It was updated to ‘Layout’ in a future release.