Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • sildee 1 post 21 karma points
    6 days ago
    sildee
    0

    Accessing image cropper in Master Page

    Hi all, I'm having some issues with a problem that sounds like it should be relatively simple. All my templates have an optional Image Cropper property with which the editor can select an image to use as a banner when desired. Currently this is implemented on one of my templates in the following way:

    @using Umbraco.Cms.Web.Common.PublishedModels;
    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.Vacature>
    @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
    @using Umbraco.Extensions;
    @{
        Layout = "MasterPage.cshtml";
         if(Model.BannerFoto is not null){
            var banner = Url.GetCropUrl(Model.BannerFoto,"Banner");
            <section>
                <div class="jumbotron jumbotron-fluid jumbotron-fluid-empty-banner mt-0 mb-0" style="background-image:url(@banner)">
                </div>
            </section>
        } else {
        } 
    }
    

    Copying this same code to the master page results in the following error:

    'IPublishedContent' does not contain a definition for 'BannerFoto' and no accessible extension method 'BannerFoto' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)

    What's causing this? I am using the same usings in both pages and I'm not sure what I'm doing wrong. Here are the usings in the master page:

    @using Umbraco.Cms.Web.Common.PublishedModels;
    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
    @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
    @using Umbraco.Extensions;
    @{
        Layout = null;
    }
    

    Any help would be much appreciated.

  • Danine Noble 80 posts 345 karma points
    6 days ago
    Danine Noble
    0

    Hullo Sildee ^^

    This is caused by the Master being a generalized, not-strongly-typed Model versus your page templates which are strongly-typed.

    Strongly-typed models give access to template fields assigned to the template like so: Model.FieldName.

    But the master template is just a general IPublishedContent model. It does not know what fields are assigned to any other model type. You can still access them but it must be done more generically.

    Such as, for your example:

    Model.Value<MediaWithCrops>("bannerFoto")
    

    The official documentation has examples for all property editors using strongly typed models and not.

Please Sign in or register to post replies

Write your reply to:

Draft