Liquid File Resolution
Liquid Pages embraces modularity by allowing templates to be defined in any C# project using the .NET IFileProvider abstraction. Each route can be backed by its own file provider, enabling a clean separation of concerns—whether you centralize all templates or distribute them across modules.
The library leverages the
IFileProviderinterface, making it possible to source templates from physical files, embedded resources, or both..When resolving a route, Liquid Pages looks for partial templates and static files exclusively within that route’s
FileProvider, keeping each route self‑contained.You can either configure a single file provider for the whole application or adopt a truly modular approach with a separate provider per route prefix.
The example below shows a custom
ILiquidFileProviderthat switches between physical files during development and embedded resources in production:
#if DEBUG
string workingDirectory = Directory.GetCurrentDirector();
string projectDirectory = Directory.GetParent(workingDirectory).Parent.Parent.FullName;
IFileProvider fileProvider = new PhysicalFileProvider(Path.Combine(projectDirectory, "Liquid"));
#else
IFileProvider fileProvider = new EmbeddedFileProvider(typeof(LiquidFileProvider).Assembly, "Kinetq.Website.Liquid");
#endif
Liquid Page FileProvider Setup
FileProviders have to be registered at startup. The way it works is you specify a file provider for any particular route prefix and that provider will apply for all the routes that match on that prefix. Here is how setup should look like:
string workingDirectory = Directory.GetCurrentDirectory();
startup.RegisterFileProvider("/", new PhysicalFileProvider(workingDirectory));
Important! The
PhysicalFileProviderdirectory needs to be where your liquid files live! When specifying the template for the liquid files it will always start at the root of the FileProvider.
