Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for implementing @section, @RenderSection #73

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

kftrans
Copy link

@kftrans kftrans commented Aug 23, 2021

These changes allow implementation of templates supporting @section and @RenderSection, which are quite widely used in razor documents, so that support may be needed if porting existing apps to RazorEngineCore. Includes an example based on the layout example at https://github.com/adoconnection/RazorEngineCore/wiki/@Include-and-@Layout (run LayoutAndSections.Test )

@ItWorksOnMyMachine
Copy link
Contributor

@adoconnection, will you accept this PR? I currently have a fork of this repo plus this update because of our broad @section use. It would be very useful to have this accepted into the main project. Thanks!

@adoconnection
Copy link
Owner

Hi @ItWorksOnMyMachine could you please share how exactly are you using it? Must be something similar to web server where you render generic template with random Layout + sections, right? Are you on NET6+ ?

For ASP.NET MVC there is strong reason Layout and Section are located in cshtml files: since controller is not resonsible for templating, cshtml file is the only place you can choose layout.

For RazorEngineCore on the other hand there is no files, so RazorEngineCore will have to go somewhere to grab Layout, it seems like a overcomlication.

Making ProjectEngineBuilderAction accessable seems to be good improvement.
I was in doubt thats why its not yet merged.

@ItWorksOnMyMachine
Copy link
Contributor

ItWorksOnMyMachine commented Jan 11, 2024

Hi @adoconnection, We are transitioning from net48 to net6 and the final bits that use net48 are from Antaris RazorEngine. We use this to generate emails for our customers. We have about 100(ish) different email templates and 10 or so different layouts we use depending on customer type. Most of these layouts use RenderSection() to include email specific html if/when relevant. Around 30 of our emails include an @section directive for things like custom login buttons and other header bits that are unique to specific user types. I forked this repo and applied this PR and everything works fine. I suppose just adding access to ProjectEngineBuilderAction would allow all of this to be done in a custom template implementation. So, perhaps that's a better solution considering how little template support you want to add directly?

@ItWorksOnMyMachine
Copy link
Contributor

@adoconnection, any thoughts on making ProjectEngineBuilderAction public? Support for sections can be left out if ProjectEngineBuilderAction is public because we can then provide our own support in our Templates. I'm currently maintaining a fork of this project just so I can access ProjectEngineBuilderAction in order to do just this.

@adoconnection
Copy link
Owner

Hi @ItWorksOnMyMachine, ProjectEngineBuilderAction should go public for sure 👍👍

@ItWorksOnMyMachine
Copy link
Contributor

Hi @ItWorksOnMyMachine, ProjectEngineBuilderAction should go public for sure 👍👍

I've create a new PR with just this and no extra functionality. #141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants