conficient / BlazorTemplater

A library that generates HTML (e.g. for emails) from Razor Components
Apache License 2.0
146 stars 16 forks source link

Can Layouts be supported? #6

Closed conficient closed 2 years ago

conficient commented 3 years ago

Razor Components support the specify of a Layout templates that wrap component output using a @Body render fragment.

Layouts can be specified in the component, e.g, @layout MyLayout - we need to see if this can be supported.

Also are we able to support a layout being passed as a parameter or set in Templater to apply to components. This might be useful if using different layouts for different brands when creating emails, for example.

conficient commented 3 years ago

An initial test suggests layouts are not working, needs further investigation .

conficient commented 2 years ago

So layouts for a component are specified using a directive, e.g.

@layout LayoutFile

This the results in an attribute added to the generated code:

    using Microsoft.AspNetCore.Components;
    [Microsoft.AspNetCore.Components.LayoutAttribute(typeof(LayoutFile))]
    public partial class LayoutComponent : Microsoft.AspNetCore.Components.ComponentBase

A template is a component that @inherits LayoutComponentBase and has a @Body parameter. If I can find a way to render the layout and set the @Body to the target top-level component we should be able to support this.