Copied to clipboard

Flag this post as spam?

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


  • lori ryan 239 posts 573 karma points
    Apr 28, 2021 @ 18:46
    lori ryan
    0

    Block Editor

    I have a listing page I want to pick up the image from the block editor which I am using as a header section on the top of every page.

    I have the following code

      @if (child.HasValue("blocks"))
                                {
                                    var childBlocks = child.Value<IEnumerable<BlockListItem>>("blocks").Take(1);
                                    var test = child.Name;
    
                                    foreach (var block in childBlocks)
                                    {
                                        var content = block.Content;
                                        var settings = block.Settings;
                                        var myimageUrl = "";
                                        if (settings.Value("Image") != null)
                                        {
                                            myimageUrl = settings.Value<IPublishedContent>("Image").Url();
                                        }
    
                                        if (myimageUrl != "")
                                        {
                                            <img src="@myimageUrl" alt="@child.Name" />
                                        }
    

    Which pretty much picks up the image and outputs it on the listing page. However when I update the image on the page its still picking up the old image - any ideas how to always pick up the latest image?

    Or a better way to do this?

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Apr 30, 2021 @ 19:52
    Marc Goodson
    1

    Hi Lori

    I think this is a bit of a bug, but I bet you could work around it like this:

    var myImage =  settings.Value<IPublishedContent>("Image");
    // get the picked image 'again' from cache
    var myPossiblyUpdatedImage = Umbraco.Media(myImage.Id);
    myImageUrl = myPossiblyUpdatedImage.Url();
    

    be interested to know if that works for you?

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft