CrestApps.Core Templates - Prompt Templates
Build General-Purpose Templates
You are a CrestApps.Core expert. Generate code and guidance for CrestApps.Core.Templates template discovery, Liquid rendering, and composition.
Guidelines
- Reference the standalone
CrestApps.Core.Templatespackage and register it withAddTemplating(...). ITemplateServicediscovers templates from registeredITemplateProviderimplementations and caches the resolved list.- Use
ITemplateService.RenderAsync(id, arguments)for registered templates andITemplateEngine.RenderAsync(template, arguments)for an in-memory Liquid string. - Register templates in code, scan
Templates/andTemplates/Prompts/withTemplateOptions.AddDiscoveryPath(...), or scan embeddedTemplates/*.mdresources withAddTemplatesFromAssembly(...). - The built-in
FluidTemplateEngineuses deny-by-default member access. Register any POCO type that Liquid must inspect throughFluid.TemplateOptions. - This is the general template engine.
crestapps-core-ai-templatesadds AI template sources, AI-profile template services, and built-in AI prompt definitions throughAddCoreAITemplating().
Registration
using CrestApps.Core.Templates.Extensions;
builder.Services
.AddTemplating(options => options
.AddDiscoveryPath(builder.Environment.ContentRootPath)
.AddTemplate(
"welcome",
"Hello {{ customer }}!",
metadata => metadata.Title = "Welcome"))
.AddTemplatesFromAssembly(typeof(Program).Assembly, source: "MyApp");
AddTemplating(...) registers ITemplateEngine as FluidTemplateEngine, ITemplateService as DefaultTemplateService, and the built-in code, file-system, and prompt-file-system providers.
Render a Registered Template
using CrestApps.Core.Templates.Services;
namespace MyApp;
public sealed class WelcomeMessageService
{
private readonly ITemplateService _templates;
public WelcomeMessageService(ITemplateService templates)
{
_templates = templates;
}
public Task<string> RenderAsync(
string customer,
CancellationToken cancellationToken = default)
{
return _templates.RenderAsync(
"welcome",
new Dictionary<string, object>
{
["customer"] = customer,
},
cancellationToken);
}
}
Compose Template Fragments
var message = await new TemplateBuilder()
.Append("Follow these instructions.")
.AppendTemplate("welcome", new Dictionary<string, object>
{
["customer"] = customer,
})
.BuildAsync(templateService, cancellationToken);
Template Locations
Templates/*.md— generic file-system templates.Templates/Prompts/*.md— system-prompt templates, including feature subdirectories.- Embedded
Templates/*.mdresources — templates loaded withAddTemplatesFromAssembly(...).
Markdown templates can include front matter for Title, Description, Category, and IsListable; their bodies support Liquid values such as {{ customer }}.