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 223 posts 554 karma points
    1 week ago
    lori ryan
    0

    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 1482 posts 9934 karma points MVP 5x c-trib
    1 week ago
    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