Copied to clipboard

Flag this post as spam?

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


  • Sowndar M 54 posts 148 karma points
    Mar 22, 2019 @ 06:40
    Sowndar M
    0

    Composition media url is not working in blog page

    I created a banner using composition. Image received the null value in blog page but it works in other pages.

    Banner Partial View

    @{
        var site = Model.Root();
        var bannerImage = Model.Value<IPublishedContent>("bannerImage");
    }
    
    @if (bannerImage != null)
    {
    
        <section class="banner">
    
            <div class="card bg-dark  border-0  text-center">
                <img class="card-img rounded-0 img-fluid" src="@bannerImage.Url" alt="Card image">
                <div class="card-img-overlay h-100 d-flex flex-column justify-content-center">
                    <h1 class="card-title">  @Model.Value("bannerTitle")</h1>
                    <p class="card-text"> @Model.Value("bannerContent")</p>
                </div>
            </div>
    
        </section>
    
    }
    

    Blog page

    @using ContentModels = Umbraco.Web.PublishedModels;
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Blog>
    @using Umbraco.Web;
    @{
        Layout = "master.cshtml";
    }
    
        @Html.Partial("~/Views/Partials/Shared/Banner.cshtml")
    
  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Mar 23, 2019 @ 15:31
    Marc Goodson
    0

    Hi Sowndar

    Which page do you have the 'bannerImage' defined on?

    Homepage or every page?

    If it's only on the site root homepage that the banner is picked then

       var site = Model.Root();   
    var bannerImage = site.Value<IPublishedContent>("bannerImage");
    

    should show the banner ok.

    If it should be a different banner picked on every page then perhaps your blog page is missing the picker?

    regards

    marc

  • Sowndar M 54 posts 148 karma points
    Mar 25, 2019 @ 05:55
    Sowndar M
    0

    I created a compositions so I can inherit from compositions to all page.

    Blog Content Pageenter image description here

    Blog Document Type

    enter image description here

    I called in blog

    enter image description here

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Mar 25, 2019 @ 14:44
    Marc Goodson
    0

    Hi Sowndar

    I've just cut and paste what you have above into a new V8.0.0 site and it all 'just works'!!

    enter image description here

    The only thing that may be difference from your example above is the @inherits statement in the banner.cshtml partial; my full partial looks like this:

    @using ContentModels = Umbraco.Web.PublishedModels;
    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        var site = Model.Root();
        var bannerImage = Model.Value<IPublishedContent>("bannerImage");
    }
    
    @if (bannerImage != null)
    {
    
        <section class="banner">
    
            <div class="card bg-dark  border-0  text-center">
                <img class="card-img rounded-0 img-fluid" src="@bannerImage.Url" alt="Card image">
                <div class="card-img-overlay h-100 d-flex flex-column justify-content-center">
                    <h1 class="card-title">  @Model.Value("bannerTitle")</h1>
                    <p class="card-text"> @Model.Value("bannerContent")</p>
                </div>
            </div>
    
        </section>
    
    }
    

    if you have the exact same inherits, then it's weird maybe try saving your image again in the backoffice, or writing out the raw id value:

    @Model.Value<string>("bannerImage")
    

    to make sure something is picked!

    regards

    Marc

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies