Skip to content

feat(templating): support {{ include }} in Scriban templates#28

Merged
tgiachi merged 1 commit into
developfrom
feature/templating-include
Jul 2, 2026
Merged

feat(templating): support {{ include }} in Scriban templates#28
tgiachi merged 1 commit into
developfrom
feature/templating-include

Conversation

@tgiachi

@tgiachi tgiachi commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

Enables {{ include 'name' }} in SquidStd.Templating. Previously the renderer used Template.RenderAsync(model), which builds a default TemplateContext with no TemplateLoader, so any include failed at runtime ("No TemplateLoader registered").

Includes now resolve from the registered templates — the same namespace as RenderByNameAsync, including the templates/**/*.tmpl auto-loaded at startup ({{ include 'partials/header' }}templates/partials/header.tmpl). In-memory, no render-time I/O, no path-traversal surface.

Changes

  • NamedTemplateLoader (Internal): a Scriban ITemplateLoader serving registered template sources; missing name → TemplateException.
  • ScribanTemplateRenderer: keeps a name → source map (_sources), renders via a TemplateContext with the loader set. Model binding preserved (same default member renamer as before). Both inline and by-name renders can include registered templates.

Test Plan

  • include resolves a registered template; from an inline template; with a model property; missing include → TemplateException; include across auto-loaded .tmpl files (5 new tests)
  • Existing model-binding tests still green (render path changed but binding identical)
  • Full suite 990/990; build 0 errors, 0 new warnings

public async Task Include_AutoLoadedFromDisk_Works()
{
using var temp = new TempDirectory();
var templatesDir = Path.Combine(temp.Path, "templates");
{
using var temp = new TempDirectory();
var templatesDir = Path.Combine(temp.Path, "templates");
Directory.CreateDirectory(Path.Combine(templatesDir, "partials"));
using var temp = new TempDirectory();
var templatesDir = Path.Combine(temp.Path, "templates");
Directory.CreateDirectory(Path.Combine(templatesDir, "partials"));
await File.WriteAllTextAsync(Path.Combine(templatesDir, "partials", "header.tmpl"), "HEADER");
Directory.CreateDirectory(Path.Combine(templatesDir, "partials"));
await File.WriteAllTextAsync(Path.Combine(templatesDir, "partials", "header.tmpl"), "HEADER");
await File.WriteAllTextAsync(
Path.Combine(templatesDir, "page.tmpl"),
@tgiachi
tgiachi merged commit 1091e95 into develop Jul 2, 2026
3 checks passed
@tgiachi
tgiachi deleted the feature/templating-include branch July 2, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants