StubbleOrg / Stubble

Trimmed down {{mustache}} templates in .NET
Other
399 stars 58 forks source link

Any idea to .net core Startup.cs Factory for StubbleBuilder? #111

Closed anisite closed 3 years ago

anisite commented 3 years ago

Hi,

How can I use Stubble in my .net core web site? All my actual dependencies are injected with .AddScoped(). Your example are do not include injection sample code.

I can't find pretty solution to create a custom Helper with HttpContext injection in that Helper.

If I want, by example write in my template : {{UserName}} and automatically read that user name in HttpContext FROM an helper... no solution ?

Thank you!

Romanx commented 3 years ago

Hi there,

Stubble is agnostic of wherever the data is provided. You could write a method of providing information from the HttpContext although i'd advise against that as it feels like something that could be abused.

You can register a stubble renderer into your DI container and resolve it in your controller. When you're providing data to your template you can pull the data off the context as you would normally in your controller.

Hopefully that helps some,

anisite commented 3 years ago

Ok, I will look into it!