Question about Partial Inheritance
# help-with-umbraco
s
I've created a banner partial in a project I am making, and I want to make it a more generic component. Originally, I had updated the inherits statement at the top so that it inherits from
<IBannerProperties>
. However, the issue is that the
modifier
variable relies on inheritance from the
<IPageSettingProperties>
composition. Is there any way I can inherit from more than one composition at a time? TIA!
Copy code
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Homepage>

@{
    var bannerTitle = String.IsNullOrWhiteSpace(Model.Subtitle) ? Model.Title : Model.Subtitle;
    var modifier = String.IsNullOrWhiteSpace(Model.ColourTheme) ? "" : $"__{Model.ColourTheme}".ToLower();
    var image = Model.Image;
}

<section class="banner @modifier">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="banner-content">
                    <h1 class="banner-title">@Model.Title</h1>
                    <p class="banner-title">@bannerTitle</p>
                </div>

                @if (image != null)
                {
                    <div class="banner-image">
                        <picture>
                            <img src="@image.Url()" alt="">
                        </picture>
                    </div>
                }
            </div>
        </div>
    </div>
</section>
d
Hi there! Are you using the modelsbuilder in source mode? If so, then you could manually create a new interface that inherits from all interfaces that you need. Then you can manually make the models inherit your new interface Finally you can make your view use your new interface to get access to properties from both compositions
s
or you could do something like var modifier = Model is IPageSettingProperties pageSettingProperties && String.IsNullOrWhiteSpace(pageSettingProperties.ColourTheme) etc.
s
Thanks both! I've just tried @skttl's solution and it is working 🙂 out of interest @D_Inventor, where would you add that interface within your project?
d
Location of C# files is pretty much irrelevant. You should follow the file structure that you use for the rest of your project. In my projects, I have a special folder with a special namespace where I store my generated files. Extensions to models that are context independent usually reside close to there.
s
That's great, thanks @D_Inventor !
5 Views