Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render pipeline is not passed to partials #126

Closed
EndOfTheSpline opened this issue Aug 5, 2022 · 1 comment · Fixed by #130
Closed

Render pipeline is not passed to partials #126

EndOfTheSpline opened this issue Aug 5, 2022 · 1 comment · Fixed by #130
Assignees
Labels
Milestone

Comments

@EndOfTheSpline
Copy link

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.

@Romanx Romanx self-assigned this Aug 11, 2022
@Romanx Romanx added the bug label Aug 11, 2022
@Romanx Romanx added this to the 1.10 milestone Aug 11, 2022
@Romanx
Copy link
Contributor

Romanx commented Aug 29, 2022

Hey @EndOfTheSpline! Thanks for your patience this has now been released to nuget as v1.10.8

Thanks for using stubble and letting us know about this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants