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 even cloud storage.Every
LiquidRoutemust specify aFileProviderthat points to the directory containing its Liquid templates and associated assets (e.g., CSS, JavaScript, images).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.
The example below shows a custom
ILiquidFileProviderthat switches between physical files during development and embedded resources in production:
public class LiquidFileProvider : ILiquidFileProvider
{
public IFileProvider GetFileProvider()
{
#if DEBUG
string workingDirectory = Directory.GetCurrentDirectory();
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
return fileProvider;
}
}
Liquid Page File Resolution
The LiquidPageModel has a default implementation for the file provider. When debugging it uses the physical file provider, and when in release mode it switches to embedded files. In order to support embedded files, you simple need to add this line to your .csproj:
<ItemGroup>
<EmbeddedResource Include="**\*.liquid" />
</ItemGroup>
Important! If you have additional static files, like CSS or Javascript files they will also need to be included as an embedded resource.
If you want to create your own FileProvider you can simply override the GetFileProvider method in your LiquidPageModel. You can either do this for every page model you have or create your own LiquidPageModel abstraction and inherit all your models from that.
