Copied to clipboard

Flag this post as spam?

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


  • Daniel 9 posts 100 karma points
    Sep 27, 2023 @ 17:17
    Daniel
    0

    Displaying an image outside the page (BLOG)

    Hey guys!

    Im looking for a way to display an article thumbnail in a news item (blog), but no luck so far.

    The article itself display the imagen without a problem using @Umbraco.Field("blogItemImage"), however when I try to call that image from a partial view macro file I get a blank space without the URL.

    The other fields (@page.Name and @page.Url) work great. I've struggling a lot with this, any info would be greatly appreciated!

    BTW: We have to keep using Umbraco 7, unfortunately the client infraestructure is very old.

    Here it is the partial view:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
    
    var startNode = Umbraco.Content(1839);
    
    try
    {
    foreach (var page in 
     startNode.Children.Where("Visible").OrderBy("CreateDate desc"))
    {
    
    <div class="col-12 col-md-4">
    <div class="cardBlog rounded" style="background-color:#f4f4f4">
    <div class="card-body nopadding">
    <img src="@Umbraco.Field("blogItemImage")" class="img-fluid mb-3">
    <h5 class="card-title px-3">@page.Name</h5>
    <a href="@page.Url" class="btn btn-primary mb-3">Explorar artículo</a>
    </div>
    </div>
    </div>
    }
    }
    catch{}
    }
    
  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Sep 27, 2023 @ 22:15
    Marc Goodson
    100

    Hi Daniel

    Soooo old now with the v7 'dynamic' syntax. Firstly Umbraco.Field will only write out values from the current page, which is why it works on your article page! - but in this macro, you are inside a foreach loop and you want to write out the image from the 'page' variable...

    So using 'dynamic' this I think would be

    @page.BlogItemImage

    But what I can't truly remember is what you'll get when you do that...

    Eg it either just works or you'll get the media object and you'll need instead:

    @page.BlogItemImage.Url

    or whether you'll just get the integer media Id... So if you get a number you need

    @Umbraco.Media(page.BlogItemImage).Url

    Sorry its been a while!

    Regards

    Marc

  • Daniel 9 posts 100 karma points
    Sep 28, 2023 @ 00:28
    Daniel
    0

    Dude...I love you. You don't have to apologize, I've been struggling with this old code for soooo long. The answer was @page.BlogItemImage.Url all along.

    Thank you so much!

Please Sign in or register to post replies

Write your reply to:

Draft