sebastienros / fluid

Fluid is an open-source .NET template engine based on the Liquid template language.
MIT License
1.39k stars 176 forks source link

Serving views from database? #390

Open aloksharma1 opened 2 years ago

aloksharma1 commented 2 years ago

Hello I am using an implementation of mikesdotnetting to render razor views from db, my engine also looks up for liquid engine when something is not found (in error message i can see the path it tried to look).

but when i save a page using .liquid extension and try to render it it still uses razor engine, what extra config is required ? this is my runtime view registration code: liquid registration :


services.Configure<FluidMvcViewOptions>(options =>
            {
                options.TemplateOptions.MemberAccessStrategy = UnsafeMemberAccessStrategy.Instance;
            });

            var mvcBuilder = services.AddMvc().AddFluid(); 

razor runtime compiler to work with db :

mvcBuilder.AddRazorRuntimeCompilation(options =>
            {
                options.FileProviders.Clear();
                options.FileProviders.Add(_CompositeFileProvider); // this here follows example of given link
            });  
sebastienros commented 2 years ago

Do you expect the liquid files to be on disk? This is what it's doing if you don't set the custom file provider also in FluidMvcViewOptions.

aloksharma1 commented 2 years ago

Do you expect the liquid files to be on disk? This is what it's doing if you don't set the custom file provider also in FluidMvcViewOptions.

no i want everything coming from database, i tried adding FluidMvcViewOptions with available dbpage provider but nothing changed.. can you help?

reach2rv commented 2 years ago

Hi @aloksharma1, kind request to share working example once issue is resolved. I am looking for something like your implementation with liquid for one of my project but not sure where to start. I went through the link given in your initial post but still working example for fluid will be appreciated.

Thanks in advance.

aloksharma1 commented 2 years ago

@reach2rv sure i will if it just works as its working with razor runtime engine :) @sebastienros were you able to look into this, as per my needs i need to pass a bunch of fileproviders to grab views from different db table locations.

reach2rv commented 2 years ago

Hi @sebastienros,

It would be really helpful if you can look into this or provide a workaround to achieve the same.

@aloksharma1 any luck with your implementation?

Thanks in advance!

sebastienros commented 2 years ago

Can you help me by creating a unit test that fails when using a "fake" file provider? There are existing ones with such a provider in the repos. I just need to see what you are doing it that is failing.

sebastienros commented 2 years ago

I might understand the issue now. Are you trying to invoke FluidParser.Parse(filename) with a template that comes from the database? Currently the options.FileProvider is only used for include tags. Is it possible that you expect the "main" template to come from the database too?

If that's the case, right now you would need to load this template by yourself, by invoking the FileProvider directly to get the template in the parser.

I will try to provide a more intuitive solution.

aloksharma1 commented 2 years ago

@sebastienros i will try to upload a mock project by sunday, and yes i am passing a fake fileprovider thats getting template from database. as i stated above, i need the ability to pass multiple providers (like we do in razor using composite file providers) & grab those templates from custom database locations for runtime processing.

i wish i could help with this, but i am stuck with too many projects at the moment (its like a marathon on my side).

awaiting your findings

sebastienros commented 2 years ago

Have you tried to set this options:

FluidViewEngineOptions.ViewsFileProvider
FluidViewEngineOptions.PartialsFileProvider

If they are not set it will use IHostingEnvironment.ContentRootFileProvider. I assume you could also set IHostingEnvironment.ContentRootFileProvider directly.

reach2rv commented 2 years ago

@aloksharma1 sorry to bother you.. are you able to implement the same? I am willing to support to get this working please let me know how I can help.

aloksharma1 commented 2 years ago

i am sorry, i am stuck on deadlines (even sundays are hell before jan) i will check these after new year.