Skip to content

Statiq.Web with Handlebars: How to Render Partials Correctly #1023

Description

@michael-jehle

I am using the Statiq.Web NuGet package to render handlebar templates into a static website.

While I like the idea of Statiq a lot, there is little to no documentation on how to actually use it.

My Statiq pipeline currently looks as follows.

await Bootstrapper
    .Factory
    .CreateDefault(args)
   
    .BuildPipeline("Render home", builder => builder
        .WithInputReadFiles("home.hbs", "Partials/*.hbs")
        .WithProcessModules(
            new RenderHandlebars()
                .WithModel(new MyModel())
                .WithPartial("head", Config.FromContext(c => c.Inputs.First(i => i.Source.Name == "head.hbs").ContentProvider.GetTextReader().ReadToEnd())))
        .WithOutputWriteFiles(".html"))
    
    .RunAsync();

This does work and all the Handlebars features (placeholders and partials) are rendered correctly.

However, it does not feel 100% clean to read the content of the partial with: .ContentProvider.GetTextReader().ReadToEnd()

Is there a way to do this more elegantly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions