Skip to content

Render pipeline is not passed to partials #126

@EndOfTheSpline

Description

@EndOfTheSpline

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.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions