While using Stubble.Helpers, I've encountered an issue that helpers are not working when used in a partial. I've traced the issue down to the PartialTokenRenderer, in particular this line:
|
await renderer.RenderAsync(context.RendererSettings.Parser.Parse(template, lineIndent: obj.LineIndent), context); |
Because the pipeline settings of the parent context are not passed to Parse (i.e. it's missing , pipeline: context.RendererSettings.ParserPipeline), partials are always rendered with a default pipeline, even if their parent had pipeline modifications.
Workaround
As this library seems a bit dead in terms of PRs/updates, a workaround is to copy the PartialTokenRenderer, then "simply" replacing the built-in renderer:
var renderer = new StubbleBuilder()
.Configure(builder =>
{
var tokenRenderers = builder.TokenRenderers;
var idx = tokenRenderers.FindIndex(p => p.GetType().FullName == "Stubble.Core.Renderers.StringRenderer.TokenRenderers.PartialTokenRenderer");
tokenRenderers.RemoveAt(idx);
tokenRenderers.Insert(idx, new FixedPartialTokenRenderer());
})
.Build();
While not exactly pretty, it gets the job done, and allows partials to use the same render pipeline that was configured for the original renderer.
While using Stubble.Helpers, I've encountered an issue that helpers are not working when used in a partial. I've traced the issue down to the
PartialTokenRenderer, in particular this line:Stubble/src/Stubble.Core/Renderers/StringRenderer/TokenRenderers/PartialTokenRenderer.cs
Line 45 in 4958ef8
Because the pipeline settings of the parent context are not passed to
Parse(i.e. it's missing, pipeline: context.RendererSettings.ParserPipeline), partials are always rendered with a default pipeline, even if their parent had pipeline modifications.Workaround
As this library seems a bit dead in terms of PRs/updates, a workaround is to copy the
PartialTokenRenderer, then "simply" replacing the built-in renderer:While not exactly pretty, it gets the job done, and allows partials to use the same render pipeline that was configured for the original renderer.