TrackableEntities / EntityFrameworkCore.Scaffolding.Handlebars

Scaffold EF Core models using Handlebars templates.
MIT License
208 stars 53 forks source link

[Question] How to exclude property from being created(Its present on base class) #152

Closed luis-cortina closed 3 years ago

luis-cortina commented 3 years ago

First time I hear of handlebars and most solutions out there are js related.

I want to exclude a property from rendering if it has a certain name. I was doing this, but not working. Any ideas?

{{#unless property-name TenantId}}

{{#each properties}}
    {{#if property-comment}}
        ///
        <summary>
            /// {{property-comment}}
            ///
        </summary>
    {{/if}}
    {{#each property-annotations}}
        {{{property-annotation}}}
    {{/each}}
    {{#unless property-name TenantId}}
        public {{property-type}} {{property-name}} { get; set; }{{#if nullable-reference-types }}
            {{#unless property-isnullable}} = default!;{{/unless}}{{/if}} 
    {{/unless}}

{{/each}}
Leosori commented 3 years ago

Both #if and #unless accept only one parameter that they will try to evaluate to a boolean result. You need to write your own block helper for such a case

Have a look at the example over at Handlebars.Net https://github.com/Handlebars-Net/Handlebars.Net#registering-block-helpers Their example is actually exactly what you want 🙂

Registering the block helper is slightly different because it's going through the helper methods of this library It is not mentioned in the docs, but there is a also method AddHandlebarsBlockHelpers() https://github.com/TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars#handlebars-helpers-and-transformers

tonysneed commented 3 years ago

Thanks @Leosori for answering this question.