RazorLight icon indicating copy to clipboard operation
RazorLight copied to clipboard

Sharing template functions

Open RedX2501 opened this issue 3 years ago • 0 comments

Looking up a lot of documentation it seems that much of the new workflow in razor with .Net Core and Blazor has the temlates being pre-compiled.

My use-case is a bit different, the user can provide their on templates which are rendered at runtime.

This has the problem that as soon as he has 2 or more templates he will probably have common functionality that he might want to use in both scripts.

With @{ await IncludeAsync(...);} it is already possible to reuse code fragment which is nice. Unfortunately you can't stored the returned value in a variable.

What I'd like to do though is to reuse (static) functions to be able to store the value. It used to be possible as indicated by this StackOverflow question and answer: https://stackoverflow.com/questions/6347447/shared-mvc-razor-functions-in-several-views

With him providing the templates to an already compiled software means that he can't extend the Model or write some new class to share the functions. Two common "solutions" I found for the problem.

I thought that it might work out of the box here with file system projects if I was lucky and all templates were inside the same dll but it seems the generated code is not like that.

So am I missing something and this feature is available but just under-documented?

If not I'd like to ask if you also think this feature request is sensible and whether we could plan to introduce it.

RedX2501 avatar Feb 05 '21 07:02 RedX2501