### Using a Custom Builder Source: https://github.com/stubbleorg/stubble/blob/master/docs/extensibility.md Instantiate Stubble with a custom builder, such as one that uses a custom renderer. This example also demonstrates configuring settings on the builder. ```csharp var stubble = new StubbleBuilder() .UseCompilationRenderer() .Configure(builder => builder.SetIgnoreCaseOnKeyLookup(true)) .Build(); ``` -------------------------------- ### Implement Custom Template Loaders Source: https://context7.com/stubbleorg/stubble/llms.txt Create custom IStubbleLoader implementations for specific template resolution needs, such as loading from the file system. This example shows a basic FileSystemLoader. ```csharp // Custom file-based loader (implement IStubbleLoader) public class FileSystemLoader : Stubble.Core.Interfaces.IStubbleLoader { private readonly string _root; public FileSystemLoader(string root) => _root = root; public string Load(string name) { var path = Path.Combine(_root, name + ".mustache"); return File.Exists(path) ? File.ReadAllText(path) : null; } public System.Threading.Tasks.ValueTask LoadAsync(string name) => new System.Threading.Tasks.ValueTask(Load(name)); public Stubble.Core.Interfaces.IStubbleLoader Clone() => new FileSystemLoader(_root); } ``` -------------------------------- ### Configuring Stubble Instance Source: https://github.com/stubbleorg/stubble/blob/master/docs/how-to.md Shows how to configure Stubble with custom settings and extensions. This example enables case-insensitive key lookups, sets a maximum recursion depth, and adds a Json.Net extension. ```csharp var stubble = new StubbleBuilder() .Configure(settings => { settings.SetIgnoreCaseOnKeyLookup(true); settings.SetMaxRecursionDepth(512); settings.AddJsonNet(); // Extension method from extension library }) .Build(); Dictionary dataHash = GetMyData(); var output = stubble.Render("{{Foo}}", dataHash); ``` -------------------------------- ### Tag Lambda Example Source: https://github.com/stubbleorg/stubble/blob/master/docs/how-to.md Demonstrates a Tag Lambda, which is a function that returns content to be rendered in place of the tag. The lambda receives dynamic context and its return value is expanded before rendering. ```csharp var obj = new { Bar = "Bar", Foo = new Func((dyn) => { return dyn.Bar; }) }; stubble.Render("{{Foo}}", obj); // Outputs: "Bar" ``` -------------------------------- ### Setting a Custom Parser Pipeline Source: https://github.com/stubbleorg/stubble/blob/master/docs/extensibility.md Configure Stubble to use a specific parser pipeline by calling `SetParserPipeline` on the `IRendererSettingsBuilder`. This allows for the addition of new tag parsers during setup. ```csharp var settings = new RendererSettings(); settings.ParserPipeline.SetParserPipeline(new ParserPipeline().Add(new MyCustomTagParser())); var stubble = new StubbleBuilder() .Configure(settings) .Build(); ``` -------------------------------- ### Creating a Custom Builder Extension Source: https://github.com/stubbleorg/stubble/blob/master/docs/extensibility.md Define an extension method on `IStubbleBuilder` to encapsulate custom builder logic, making it discoverable and easy to use. This example shows how to introduce a custom compilation renderer. ```csharp public static class CustomBuilderExtensions { public static StubbleCompilationBuilder UseCompilationRenderer(this IStubbleBuilder builder) { return new StubbleCompilationBuilder(); } } ``` -------------------------------- ### Section Lambda Examples Source: https://github.com/stubbleorg/stubble/blob/master/docs/how-to.md Illustrates different types of Section Lambdas. These lambdas wrap sections of a template, and their behavior varies based on the function signature, allowing for conditional rendering or template manipulation. ```csharp var obj = new { Bar = "Bar", Foo = new Func((dyn, str) => { return str.Replace("World", dyn.Bar); }) }; stubble.Render("{{#Foo}} Hello World {{/Foo}}", obj); //Outputs: " Hello Bar " var obj2 = new { Bar = "Bar", Foo = new Func((str) => { return "Foo {{Bar}}"; }) }; stubble.Render("{{#Foo}} Hello World {{/Foo}}", obj2); //Outputs: "Foo Bar" var obj3 = new { Bar = "Bar", Foo = new Func, object>((str, render) => { return "Foo " + render("{{Bar}}"); }) }; stubble.Render("{{#Foo}} Hello World {{/Foo}}", obj3); //Outputs: "Foo Bar" ``` -------------------------------- ### Standard Sync and Async Rendering Source: https://github.com/stubbleorg/stubble/blob/master/docs/how-to.md Demonstrates how to render templates synchronously and asynchronously using Stubble, either from a file stream or a string. Ensure the template file exists at the specified path. ```csharp using Stubble.Core.Builders; using System.IO; using System.Text; // Sync public void SyncRender() { var stubble = new StubbleBuilder().Build(); var myObj = new MyObj(); using (StreamReader streamReader = new StreamReader(@".\Path\To\My\File.Mustache", Encoding.UTF8)) { var output = stubble.Render(streamReader.ReadToEnd(), myObj); // Do Stuff } } // Async public async Task RenderAsync() { var stubble = new StubbleBuilder().Build(); var myObj = new MyObj(); using (StreamReader streamReader = new StreamReader(@".\Path\To\My\File.Mustache", Encoding.UTF8)) { var content = await streamReader.ReadToEndAsync(); var output = await stubble.RenderAsync(content, myObj); // Do Stuff } } ``` ```csharp var stubble = new StubbleBuilder().Build(); Dictionary dataHash = GetMyData(); //Sync var output = stubble.Render("{{Foo}}", dataHash); // Async var output = await stubble.RenderAsync("{{Foo}}", dataHash); ``` -------------------------------- ### Compile and Render Templates with Stubble Source: https://github.com/stubbleorg/stubble/blob/master/docs/compilation.md Demonstrates how to compile a template into a function for both synchronous and asynchronous rendering. The compiled function can be reused for multiple data items, improving performance. Ensure you have the StubbleCompilationBuilder and necessary data types. ```csharp var stubble = new StubbleCompilationBuilder().Build(); MyData data = GetMyData(); // Sync Func renderFunc = stubble.Compile("{{Foo}}", data); // Async Func renderFunc = stubble.CompileAsync("{{Foo}}", data); // Later var builder = new StringBuilder(); foreach(MyData dataItem in LoadLotsOfData()) { builder.Append(renderFunc(dataItem)); } return builder.ToString(); ``` -------------------------------- ### Build Stubble Renderer with StubbleBuilder Source: https://context7.com/stubbleorg/stubble/llms.txt Use StubbleBuilder to create a StubbleVisitorRenderer instance. Configure settings like case-insensitivity, recursion depth, and partial template loaders before building the renderer. A zero-configuration build is also possible. ```csharp using Stubble.Core.Builders; using Stubble.Core.Settings; using System.Collections.Generic; // Zero-config renderer var stubble = new StubbleBuilder().Build(); // Fully configured renderer var stubbleConfigured = new StubbleBuilder() .Configure(settings => { settings.SetIgnoreCaseOnKeyLookup(true); settings.SetMaxRecursionDepth(512); settings.SetEncodingFunction(s => System.Web.HttpUtility.HtmlEncode(s)); settings.AddToPartialTemplateLoader(new DictionaryLoader(new Dictionary { ["header"] = "

{{Title}}

", ["footer"] = "
{{Year}}
" })); }) .Build(); ``` -------------------------------- ### StubbleBuilder - Building the Standard Renderer Source: https://context7.com/stubbleorg/stubble/llms.txt The StubbleBuilder is used to create instances of StubbleVisitorRenderer. It allows for configuration of settings before building the renderer. ```APIDOC ## StubbleBuilder ### Description Used to create a `StubbleVisitorRenderer` instance. Call `.Configure()` to supply settings and `.Build()` to produce the renderer. All settings are optional. ### Usage ```csharp using Stubble.Core.Builders; // Zero-config renderer var stubble = new StubbleBuilder().Build(); // Fully configured renderer var stubbleConfigured = new StubbleBuilder() .Configure(settings => { settings.SetIgnoreCaseOnKeyLookup(true); settings.SetMaxRecursionDepth(512); settings.SetEncodingFunction(s => System.Web.HttpUtility.HtmlEncode(s)); settings.AddToPartialTemplateLoader(new DictionaryLoader(new Dictionary { ["header"] = "

{{Title}}

", ["footer"] = "
{{Year}}
" })); }) .Build(); ``` ``` -------------------------------- ### Configure Per-Render Overrides with RenderSettings Source: https://context7.com/stubbleorg/stubble/llms.txt Adjust rendering behavior on a per-call basis using RenderSettings. Options include throwing exceptions on missing data, skipping HTML encoding, and specifying culture-specific formatting. ```csharp using Stubble.Core.Builders; using Stubble.Core.Settings; using Stubble.Core.Exceptions; var stubble = new StubbleBuilder().Build(); var view = new { Name = "Alice", Role = "admin" }; // Throw on missing keys (default: silently omit) try { var strict = new RenderSettings { ThrowOnDataMiss = true }; string result = stubble.Render("{{Name}} - {{MissingKey}}", view, strict); } catch (StubbleDataMissException ex) { Console.WriteLine($"Missing key: {ex.Message}"); } // Skip HTML encoding for trusted content var trusted = new RenderSettings { SkipHtmlEncoding = true }; string raw = stubble.Render("{{Name}}", view, trusted); // => "Alice" (no <b> escaping) // Culture-aware number rendering var cultural = new RenderSettings { CultureInfo = System.Globalization.CultureInfo.GetCultureInfo("de-DE") }; string price = stubble.Render("Price: {{Amount}}", new { Amount = 1234.5 }, cultural); // => "Price: 1234,5" (German decimal separator) ``` -------------------------------- ### Use DictionaryLoader and CompositeLoader for Partials Source: https://context7.com/stubbleorg/stubble/llms.txt Manage partial templates using DictionaryLoader for in-memory strings or CompositeLoader to chain multiple loaders, such as a DictionaryLoader and a custom FileSystemLoader. The CompositeLoader checks loaders in reverse order of addition. ```csharp using Stubble.Core.Builders; using Stubble.Core.Loaders; using Stubble.Core.Exceptions; using System.Collections.Generic; using System.IO; // DictionaryLoader — static in-memory partials var dict = new DictionaryLoader(new Dictionary { ["btn"] = "", ["icon"] = "" }); // CompositeLoader — dictionary takes priority, falls back to file system var composite = new CompositeLoader( new FileSystemLoader(@".\templates"), dict); // added last = checked first (reverse iteration) var stubble = new StubbleBuilder() .Configure(s => s.SetPartialTemplateLoader(composite)) .Build(); try { string result = stubble.Render("{{>btn}}{{>missing}}", new { Label = "Click Me" }); } catch (UnknownTemplateException ex) { Console.WriteLine($"Template not found: {ex.Message}"); } ``` -------------------------------- ### Stubble Template Compilation for Performance Source: https://context7.com/stubbleorg/stubble/llms.txt Compile templates once using StubbleCompilationBuilder for significant performance gains in hot render loops. Subsequent renders are pure .NET delegate invocations. ```csharp using Stubble.Compilation.Builders; using System.Text; public class Tweet { public string Author { get; set; } public string Body { get; set; } public int Retweets { get; set; } } var stubble = new StubbleCompilationBuilder().Build(); // Compile once Func renderTweet = stubble.Compile( "@{{Author}}: {{Body}} ({{Retweets}} retweets)", new Tweet()); // type-sample only, values are ignored // Render many times at full speed var tweets = LoadTimeline(); // returns IEnumerable var sb = new StringBuilder(); foreach (var tweet in tweets) { sb.Append(renderTweet(tweet)); } return sb.ToString(); // Async compilation Func renderAsync = await stubble.CompileAsync( "@{{Author}}: {{Body}}", new Tweet()); ``` -------------------------------- ### Asynchronous Rendering with StubbleVisitorRenderer.RenderAsync Source: https://context7.com/stubbleorg/stubble/llms.txt Perform asynchronous rendering using RenderAsync, which returns Task. This method supports async partial loaders and async I/O pipelines, suitable for scenarios involving file I/O or other asynchronous operations. ```csharp using Stubble.Core.Builders; using System.IO; using System.Text; using System.Threading.Tasks; var stubble = new StubbleBuilder().Build(); public async Task RenderFromFileAsync(string path, object viewModel) { using var reader = new StreamReader(path, Encoding.UTF8); string template = await reader.ReadToEndAsync(); return await stubble.RenderAsync(template, viewModel); } // Usage var invoice = new { CustomerName = "Acme Corp", Total = 1234.56m, Lines = new[] { new { Description = "Widget A", Qty = 10, Price = 99.99m }, new { Description = "Widget B", Qty = 5, Price = 46.82m } }}; string html = await RenderFromFileAsync(@".\templates\invoice.mustache", invoice); ``` -------------------------------- ### Registering a Custom ValueGetter Source: https://github.com/stubbleorg/stubble/blob/master/docs/extensibility.md Add a custom Func to Stubble's builder to define how specific types are accessed by a key. The Func signature is `Func(key, value, ignoreCase) => object`. ```csharp var stubble = new StubbleBuilder() .ValueGetters .Register((key, value, ignoreCase) => { // Custom logic to retrieve value from MyCustomType return "some value"; }) .Build(); ``` -------------------------------- ### Configure Renderer Settings with RendererSettingsBuilder Source: https://context7.com/stubbleorg/stubble/llms.txt Use RendererSettingsBuilder to customize Stubble's rendering behavior, such as case-insensitive lookups, recursion depth, custom delimiters, value getters, truthy checks, enumeration conversions, and partial template loaders. ```csharp using Stubble.Core.Builders; using Stubble.Core.Loaders; using System; using System.Collections; using System.Collections.Generic; using System.Data; var stubble = new StubbleBuilder() .Configure(s => { // Case-insensitive key lookup (slightly slower) s.SetIgnoreCaseOnKeyLookup(true); // Custom recursion depth limit (default: 256; 0 = uint.MaxValue) s.SetMaxRecursionDepth(128); // Override default {{ }} delimiters s.SetDefaultTags(new Stubble.Core.Classes.Tags("<%%", "%%>")); // Custom value getter — teach Stubble how to read DataRow columns s.AddValueGetter(typeof(DataRow), (key, obj, ignoreCase) => { var row = (DataRow)obj; var col = ignoreCase ? row.Table.Columns.Cast() .FirstOrDefault(c => c.ColumnName.Equals(key, StringComparison.OrdinalIgnoreCase)) ?.ColumnName : key; return col != null && row.Table.Columns.Contains(col) ? row[col] : null; }); // Custom truthy check — DataTable is truthy when it has rows s.AddTruthyCheck(t => t.Rows.Count > 0); // Custom enumeration converter — DataTable rows become IEnumerable s.AddEnumerationConversion(typeof(DataTable), obj => ((DataTable)obj).Rows.Cast()); // Partial template loader backed by a dictionary s.SetPartialTemplateLoader(new DictionaryLoader(new Dictionary { ["nav"] = "", ["head"] = "{{Title}}" })); }) .Build(); ``` -------------------------------- ### StubbleCompilationBuilder / StubbleCompilationRenderer.Compile Source: https://context7.com/stubbleorg/stubble/llms.txt Compile templates once using StubbleCompilationRenderer for high-performance rendering in hot loops. Compiled templates are represented as Func delegates. ```APIDOC ## StubbleCompilationBuilder / StubbleCompilationRenderer.Compile — Template Compilation `StubbleCompilationRenderer` compiles a template + data type pair into a `Func` once; subsequent calls are pure .NET delegate invocations with no parsing overhead. Ideal for hot render loops. ```csharp using Stubble.Compilation.Builders; using System.Text; public class Tweet { public string Author { get; set; } public string Body { get; set; } public int Retweets { get; set; } } var stubble = new StubbleCompilationBuilder().Build(); // Compile once Func renderTweet = stubble.Compile( "@{{Author}}: {{Body}} ({{Retweets}} retweets)", new Tweet()); // type-sample only, values are ignored // Render many times at full speed var tweets = LoadTimeline(); // returns IEnumerable var sb = new StringBuilder(); foreach (var tweet in tweets) { sb.Append(renderTweet(tweet)); } return sb.ToString(); // Async compilation Func renderAsync = await stubble.CompileAsync( "@{{Author}}: {{Body}}", new Tweet()); ``` ``` -------------------------------- ### StaticStubbleRenderer: Direct Static Rendering Source: https://context7.com/stubbleorg/stubble/llms.txt Use StaticStubbleRenderer for simple, one-off renders without builder configuration. It supports direct static calls for basic string interpolation and rendering with partials. ```csharp using Stubble.Core; // Direct static call — no instantiation needed string output = StaticStubbleRenderer.Render("Hello, {{Name}}!", new { Name = "World" }); // => "Hello, World!" // With partials var partials = new Dictionary { ["sig"] = "-- {{Author}}" }; string email = StaticStubbleRenderer.Render( "Dear {{Recipient}},\n\nBest regards\n{{>sig}}", new { Recipient = "Bob", Author = "Alice" }, partials); // => "Dear Bob,\n\nBest regards\n-- Alice" ``` -------------------------------- ### Synchronous Rendering with StubbleVisitorRenderer.Render Source: https://context7.com/stubbleorg/stubble/llms.txt Process a Mustache template string against a .NET object or IDictionary using Render. Supports inline partials and per-call RenderSettings like ThrowOnDataMiss and SkipHtmlEncoding. HTML encoding is enabled by default. ```csharp using Stubble.Core.Builders; using Stubble.Core.Settings; using System.Collections.Generic; var stubble = new StubbleBuilder().Build(); // Render against a typed object var person = new { Name = "Alice", Age = 30, IsAdmin = true }; string result = stubble.Render( "Name: {{Name}}, Age: {{Age}}{{#IsAdmin}} [admin]{{/IsAdmin}}", person); // => "Name: Alice, Age: 30 [admin]" // Render against a dictionary var data = new Dictionary { ["Title"] = "Hello World", ["Items"] = new[] { new { Label = "One" }, new { Label = "Two" } } }; string list = stubble.Render( "{{Title}}\n{{#Items}}- {{Label}}\n{{/Items}}", data); // => "Hello World\n- One\n- Two\n" // With inline partials and per-call settings var partials = new Dictionary { ["greeting"] = "Hi, {{Name}}!" }; var renderSettings = new RenderSettings { ThrowOnDataMiss = true, // throw StubbleDataMissException on missing keys SkipHtmlEncoding = false, // HTML-encode interpolated values (default) SkipRecursiveLookup = true // disable parent-context lookup for speed }; string withPartial = stubble.Render("{{>greeting}}", person, partials, renderSettings); // => "Hi, Alice!" ``` -------------------------------- ### StaticStubbleRenderer Source: https://context7.com/stubbleorg/stubble/llms.txt Use StaticStubbleRenderer for simple, one-off renders without needing to configure a builder. It wraps a lazily initialized singleton StubbleVisitorRenderer. ```APIDOC ## StaticStubbleRenderer — Zero-Setup Static API `StaticStubbleRenderer` wraps a lazily initialised singleton `StubbleVisitorRenderer`. Use it for simple, one-off renders where configuring a builder is unnecessary. ```csharp using Stubble.Core; // Direct static call — no instantiation needed string output = StaticStubbleRenderer.Render("Hello, {{Name}}!", new { Name = "World" }); // => "Hello, World!" // With partials var partials = new Dictionary { ["sig"] = "-- {{Author}}" }; string email = StaticStubbleRenderer.Render( "Dear {{Recipient}},\n\nBest regards\n{{>sig}}", new { Recipient = "Bob", Author = "Alice" }, partials); // => "Dear Bob,\n\nBest regards\n-- Alice" ``` ``` -------------------------------- ### StubbleVisitorRenderer.RenderAsync - Asynchronous Rendering Source: https://context7.com/stubbleorg/stubble/llms.txt Asynchronously processes a Mustache template string against a view model, returning a Task. Supports async partial loaders and async I/O pipelines. ```APIDOC ## StubbleVisitorRenderer.RenderAsync ### Description Asynchronously processes a Mustache template string against any .NET object or `IDictionary` and returns a `Task`. Supports async partial loaders and async I/O pipelines. ### Method `Task RenderAsync(string template, object view)` `Task RenderAsync(string template, object view, IDictionary partials)` `Task RenderAsync(string template, object view, IDictionary partials, RenderSettings settings)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp using Stubble.Core.Builders; using System.IO; using System.Text; using System.Threading.Tasks; var stubble = new StubbleBuilder().Build(); public async Task RenderFromFileAsync(string path, object viewModel) { using var reader = new StreamReader(path, Encoding.UTF8); string template = await reader.ReadToEndAsync(); return await stubble.RenderAsync(template, viewModel); } // Usage var invoice = new { CustomerName = "Acme Corp", Total = 1234.56m, Lines = new[] { new { Description = "Widget A", Qty = 10, Price = 99.99m }, new { Description = "Widget B", Qty = 5, Price = 46.82m } }}; string html = await RenderFromFileAsync(@".\templates\invoice.mustache", invoice); ``` ### Response #### Success Response (200) - **Task**: A task that represents the asynchronous operation, containing the rendered template as a string. ``` -------------------------------- ### Lambdas Source: https://context7.com/stubbleorg/stubble/llms.txt Stubble supports Tag Lambdas and Section Lambdas. Tag lambdas replace a {{tag}} at render time, while Section Lambdas wrap a {{#section}} block, receiving the raw section text. ```APIDOC ## Lambdas — Tag and Section Lambdas Stubble is v1.1.2 lambda-spec compliant. **Tag lambdas** (`Func` or `Func`) replace a `{{tag}}` at render time. **Section lambdas** wrap a `{{#section}}` block — the raw section text (and optionally a render helper) is passed in. ```csharp using Stubble.Core.Builders; using System; var stubble = new StubbleBuilder().Build(); // Tag lambda: return value replaces the tag; returned tags are re-expanded var tagLambda = new { Name = "World", Shout = new Func(ctx => ctx.Name.ToString().ToUpper()) }; stubble.Render("{{Shout}}!", tagLambda); // => "WORLD!" // Section lambda: receives raw inner text var sectionLambda = new { Lang = "en", Wrap = new Func(inner => $"{inner.Trim()}") }; stubble.Render("{{#Wrap}} Hello World {{/Wrap}}", sectionLambda); // => "Hello World" // Section lambda with render helper — re-renders inner text as a template var withRender = new { Bar = "Bar", Foo = new Func, object>( (inner, render) => "Prefix: " + render("{{Bar}}")) }; stubble.Render("{{#Foo}} ignored {{/Foo}}", withRender); // => "Prefix: Bar" ``` ``` -------------------------------- ### Build Custom Parser Pipeline Source: https://github.com/stubbleorg/stubble/blob/master/docs/parser-pipelines.md Use the `ParserPipelineBuilder` to modify the default parser pipeline. You can replace existing parsers with custom ones, remove parsers entirely, or add new parsers before or after specific existing parsers. ```csharp var builder = new ParserPipelineBuilder(); builder.Replace(new MyCustomParser()); // OR builder.Remove(); // OR builder.AddAfter(new MyCustomParser()); builder.AddBefore(new MyCustomParser()); var pipeline = builder.Build(); ``` -------------------------------- ### StubbleVisitorRenderer.Render - Synchronous Rendering Source: https://context7.com/stubbleorg/stubble/llms.txt Processes a Mustache template string against a view model synchronously, returning the rendered string. Supports inline partials and per-call render settings. ```APIDOC ## StubbleVisitorRenderer.Render ### Description Synchronously processes a Mustache template string against any .NET object or `IDictionary` and returns the rendered string. Overloads accept inline partials and per-call `RenderSettings`. ### Method `string Render(string template, object view)` `string Render(string template, object view, IDictionary partials)` `string Render(string template, object view, IDictionary partials, RenderSettings settings)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp using Stubble.Core.Builders; using Stubble.Core.Settings; using System.Collections.Generic; var stubble = new StubbleBuilder().Build(); // Render against a typed object var person = new { Name = "Alice", Age = 30, IsAdmin = true }; string result = stubble.Render( "Name: {{Name}}, Age: {{Age}}{{#IsAdmin}} [admin]{{/IsAdmin}}", person); // => "Name: Alice, Age: 30 [admin]" // Render against a dictionary var data = new Dictionary { ["Title"] = "Hello World", ["Items"] = new[] { new { Label = "One" }, new { Label = "Two" } } }; string list = stubble.Render( "{{Title}}\n{{#Items}}- {{Label}}\n{{/Items}}", data); // => "Hello World\n- One\n- Two\n" // With inline partials and per-call settings var partials = new Dictionary { ["greeting"] = "Hi, {{Name}}!" }; var renderSettings = new RenderSettings { ThrowOnDataMiss = true, // throw StubbleDataMissException on missing keys SkipHtmlEncoding = false, // HTML-encode interpolated values (default) SkipRecursiveLookup = true // disable parent-context lookup for speed }; string withPartial = stubble.Render("{{>greeting}}", person, partials, renderSettings); // => "Hi, Alice!" ``` ### Response #### Success Response (200) - **string**: The rendered template as a string. ``` -------------------------------- ### Tag and Section Lambdas in Stubble Source: https://context7.com/stubbleorg/stubble/llms.txt Stubble supports lambda functions for dynamic tag replacement and section content processing. Tag lambdas replace {{tag}}, while section lambdas receive the raw inner text and can optionally re-render it. ```csharp using Stubble.Core.Builders; using System; var stubble = new StubbleBuilder().Build(); // Tag lambda: return value replaces the tag; returned tags are re-expanded var tagLambda = new { Name = "World", Shout = new Func(ctx => ctx.Name.ToString().ToUpper()) }; stubble.Render("{{Shout}}!", tagLambda); // => "WORLD!" // Section lambda: receives raw inner text var sectionLambda = new { Lang = "en", Wrap = new Func(inner => $"{inner.Trim()}") }; stubble.Render("{{#Wrap}} Hello World {{/Wrap}}", sectionLambda); // => "Hello World" // Section lambda with render helper — re-renders inner text as a template var withRender = new { Bar = "Bar", Foo = new Func, object>( (inner, render) => "Prefix: " + render("{{Bar}}")) }; stubble.Render("{{#Foo}} ignored {{/Foo}}", withRender); // => "Prefix: Bar" ``` -------------------------------- ### Customize Parser Pipeline with ParserPipelineBuilder Source: https://context7.com/stubbleorg/stubble/llms.txt Use ParserPipelineBuilder to replace, insert, or remove tag parsers in the Mustache tokenization process. This allows for custom parsing logic or disabling specific features like comments. ```csharp using Stubble.Core.Builders; using Stubble.Core.Parser.TokenParsers; var stubble = new StubbleBuilder() .Configure(s => { s.ConfigureParserPipeline(pipeline => { // Replace the built-in interpolation parser with a custom one pipeline.Replace(new MyCustomInterpolationParser()); // Or insert before/after an existing parser // pipeline.AddBefore(new MyPrefixParser()); // pipeline.AddAfter(new MySectionExtensionParser()); // Or remove a parser entirely (e.g., disable comments) // pipeline.Remove(); }); }) .Build(); // For standalone parsing (without rendering), build the pipeline separately var pipelineBuilder = new ParserPipelineBuilder(); pipelineBuilder.Remove(); var pipeline = pipelineBuilder.Build(); // Pass it directly to the static parser for AST-only use var ast = Stubble.Core.Parser.MustacheParser.Parse( "Hello {{Name}}", new Stubble.Core.Classes.Tags("{{ ", " }}"), pipeline); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.