Copied to clipboard

Flag this post as spam?

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


  • Jeppe Volander Rasmussen 16 posts 138 karma points
    Jul 18, 2018 @ 16:31
    Jeppe Volander Rasmussen
    0

    Display a blogpost images

    Hello all,

    im trying to display 4 blog posts on the frontpage - I managed to pull out their name and url with "item" method. But I have other data i want to display aswell. Like name of the author and the blog image, but im kinda lost - can you help?

    enter image description here

        var selection = Model.Content.Site().FirstChild("blog").Children("blogpost")
                            .Where(x => x.IsVisible());
    
    @foreach(var item in selection){
    
            <div class="col-sm-3">
                <div class="card">
    
                    <div class="card-body">
                        <h5 class="card-title">@item.Name</h5>
                        <a class="button button--small" href="@item.Url">Se opskrift</a>
                    </div>
                </div>
            </div>
        }
    
  • Pedro Mendes 53 posts 258 karma points
    Jul 18, 2018 @ 17:02
    Pedro Mendes
    0

    Are you using models builder?

    If not, have you tried @item.GetPropertyValue("PROPERTY_ALIAS") ?

  • Jeppe Volander Rasmussen 16 posts 138 karma points
    Jul 18, 2018 @ 18:07
    Jeppe Volander Rasmussen
    0

    Dont even know what that is :s

    Yeah i tried that, it returns the id of the media, which is great. Then i tried doing something like below, where i enter the id manually. But i cant figure out on how to do it dynamically.

     <img src="@Umbraco.Media(1144).Url" alt="A blog post" class="img-responsive" />
    
  • Pedro Mendes 53 posts 258 karma points
    Jul 18, 2018 @ 18:14
    Pedro Mendes
    0

    what about

    @item.GetPropertyValue<IPublishedContent>("PROPERTY_ALIAS").Url 
    
  • Jeppe Volander Rasmussen 16 posts 138 karma points
    Jul 18, 2018 @ 18:17
    Jeppe Volander Rasmussen
    0

    Causes a runtime error :s

     <img src="@item.GetPropertyValue<IPublishedContent>("imageBlog").Url" alt="A blog post" class="img-responsive" />
    
  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Jul 18, 2018 @ 18:49
    Alex Skrypnyk
    101

    Hi Jeppe

    Try this:

    <img src="@Umbraco.TypedMedia(item.GetPropertyValue<int>("imageBlog")).Url" alt="A blog post" class="img-responsive" />
    

    Thanks,

    Alex

  • Jeppe Volander Rasmussen 16 posts 138 karma points
    Jul 18, 2018 @ 18:53
    Jeppe Volander Rasmussen
    0

    Still the same Alex, i get runtime error :S

  • Jeppe Volander Rasmussen 16 posts 138 karma points
    Jul 18, 2018 @ 19:09
    Jeppe Volander Rasmussen
    0

    This one did the trick! - had to restart my "uaas watch" for some reason, it didn't want to update the changes!

    Thanks Alex!

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Jul 18, 2018 @ 18:55
    Alex Skrypnyk
    0

    What error says?

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Jul 18, 2018 @ 18:56
    Alex Skrypnyk
    0
    var mediaItem = Umbraco.TypedMedia(item.GetPropertyValue<int>("imageBlog"));
        if (mediaItem != null)
        {
        <img src = "@mediaItem.Url" alt = "A blog post" class="img-responsive" />
        }
    

    Did you add image to Umbraco?

  • Jeppe Volander Rasmussen 16 posts 138 karma points
    Jul 18, 2018 @ 19:00
    Jeppe Volander Rasmussen
    0

    I get YSOD everytime, cant see the error itself I get an error on both your codes :s

    enter image description here

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Jul 18, 2018 @ 19:11
    Alex Skrypnyk
    0

    Can you debug this code?

    Or try to add

  • 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