adoconnection / RazorEngineCore

.NET6 Razor Template Engine
MIT License
565 stars 84 forks source link

Layout + html safe extension #87

Closed adoconnection closed 2 years ago

adoconnection commented 2 years ago

@adoconnection , I seem to have a problem after following the layout + html safe templating docs whereby the @RenderBody() portion is html encoded... any suggestions?

It's like it's encoding the @RenderBody() part when it's already safe/encoded.

Edit: I think I have a solution, shout out if I'm missing any issues though.

  1. Modify MyTemplateBase<T> Include and RenderBody methods to return object and be virtual.
  2. Modify MyHtmlTemplateBase<T> (which inherits MyTemplateBase<T>) by overriding those two methods and have them return Raw(base.Include/RenderBody);.
  3. Need to move RawContent into its own internal class as it was previously private inside MyTemplateBase.

Like this, when WriteAsync is called with the RenderBody() or Include() result, it's already a RawContent and the avoidance of html encoding happens.

Hope that helps someone else. Almost wonder if it's worth adding this into the docs.

Originally posted by @benmccallum in https://github.com/adoconnection/RazorEngineCore/issues/65#issuecomment-954703223

adoconnection commented 2 years ago

@benmccallum I moved your last comment to a new issue. Please drop a line if the problem is solved or not.

benmccallum commented 2 years ago

Thanks @adoconnection , sorry for piling on another issue :P

I've resolved my issue, but should we get my gist into a sample app or documentation so this combo is clear to setup for folks?

benmccallum commented 2 years ago

Gosh, sorry I'm not sure how I missed the extensions part of the readme which points to: https://github.com/wdcossey/RazorEngineCore.Extensions

Perhaps I should've just used that all along 🤦🏻‍♂️

adoconnection commented 2 years ago

No worries

benmccallum commented 2 years ago

Feel free to close this if you'd prefer to point to the other package. Here's my gist again for anyone it helps.

adoconnection commented 2 years ago

👌👌