Copied to clipboard

Flag this post as spam?

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


  • mikkel 143 posts 365 karma points
    Oct 04, 2017 @ 13:05
    mikkel
    0

    I cant retrieve my images

    Hi every one. I'm doing a partial view to show 8 of my projects. It should do it on the front of my website. A small thumbnail image with a title below and a link to the project must be displayed. I can not capture my pictures. what am I doing wrong?. I have followed this guide here

    Typed Example (multiple disabled):

    https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/media-picker#typed-example-multiple-disabled

    Here is my code:

        @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        if (CurrentPage.Children.Any())
        {
            <h4>Cases</h4>
            var nyeste = Umbraco.TypedContent(1094).Children().OrderBy(x => x.CreateDate).RandomOrder();
            <div class="for-group">
                @foreach (var item in nyeste)
                {
                    <div class="col-md-3">
                        <!-- 1 image -->
                        @{
                            var Caseimg = Model.Content.GetPropertyValue<IPublishedContent>
                                ("caseBillede");
                            if (Caseimg != null)
                            {
                                <img src="@Caseimg.Url" style="width:200px" alt="@Caseimg.GetPropertyValue("alt")" />
                            }
                        }
    
                        <!-- 2 Title -->
                        <p>@item.Name</p>
    
                        <!-- 3 link -->
                        <a href="@item.Url" class="btn btn-default">Læs mere</a>
                    </div>
                 }
            </div>
         }
    
    }
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Oct 04, 2017 @ 14:52
    Alex Skrypnyk
    0

    Hi Mikkel

    What property editor are you using in "caseBillede" field?

    What version of Umbraco are you using? If Property Values Converters are disabled in your solution, the code should look like that:

                    <!-- 1 image -->
                    @{
                        var caseimgId = Model.Content.GetPropertyValue<int>("caseBillede");
                        if (caseimgId  > 0)
                        {
                            var mediaItem = Umbraco.TypedMedia(caseimgId);
                            if (mediaItem != null)
                            {
                                <img src="@mediaItem.Url" style="width: 200px" alt="@mediaItem.GetPropertyValue("alt")"/>
                            }
                        }
                    }
    

    Thanks,

    Alex

  • mikkel 143 posts 365 karma points
    Oct 04, 2017 @ 18:49
    mikkel
    0

    Hi Alex when you say proberty editor you mean like mediapicker?

    i am using mediapicker to my images. It dont work with you code you can se my documen t type on the image. enter image description here

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Oct 04, 2017 @ 20:09
    Alex Skrypnyk
    0

    As I see on the screen there is no selected image in media picker.

    Alex

  • Craig Mayers 164 posts 508 karma points
    Oct 04, 2017 @ 21:59
    Craig Mayers
    0

    Hi Mikkel,

    The following code should do the trick for you:

        var caseImageNode = item.GetPropertyValue<IPublishedContent>"caseBillede");
        var caseImage = Umbraco.TypedMedia(caseImageNode.Id);
        if (caseImage != null)
        {
            <img src="@caseImage.Url" style="width:200px" alt="@caseImage.GetPropertyValue("alt")" />
        }
    

    Craig

  • mikkel 143 posts 365 karma points
    Oct 05, 2017 @ 08:11
    mikkel
    0

    Do i have to have a selected image when it is a document type?.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Oct 05, 2017 @ 08:14
    Alex Skrypnyk
    0

    Hi Mikkel,

    You have to select the image in the content tree, select image on the page that you are working on.

    Thanks,

    Alex

  • Craig Mayers 164 posts 508 karma points
    Oct 05, 2017 @ 11:03
    Craig Mayers
    0

    Hi Mikkel,

    I think Alex confused you slightly, you're right, the screenshot you upload was off the DocType in Settings. This looks fine as you are using a MediaPicker control.

    Now, in the Content section of the CMS for each CASE page, just ensure you set an image for each node.

    Then you can use the code I sent the other day.

    Regards

    Craig

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Oct 05, 2017 @ 11:16
    Alex Skrypnyk
    100

    Hi

    Mikkel, sorry, I really didn't realize that screen is from settings section, that's why I asked for uploading the image, Craig is right maybe I confused you.

    Craig, regarding your code:

    var caseImageNode = item.GetPropertyValue<IPublishedContent>"caseBillede");
        var caseImage = Umbraco.TypedMedia(caseImageNode.Id);
        if (caseImage != null)
        {
            <img src="@caseImage.Url" style="width:200px" alt="@caseImage.GetPropertyValue("alt")" />
        }
    

    Why do we need to call Umbraco.TypedMedia(caseImageNode.Id)? It's not needed call, we will have the same result with this code:

    if (item.HasValue("caseBillede"))
    {
        var caseImageNode = item.GetPropertyValue<IPublishedContent>("caseBillede");
        <img src="@caseImageNode.Url" style="width: 200px" alt="@caseImageNode.GetPropertyValue("alt")"/>
    }
    

    I hope it makes sense.

    Thanks,

    Alex

  • mikkel 143 posts 365 karma points
    Oct 05, 2017 @ 11:54
    mikkel
    0

    Hi Alex. I got a little confused about it. I tried your code Craig but it would not work either. I'm getting a error on the semicolon, I've tried to remove, but of course it will not work. :) I have make 2 screenshots so you can see my code and the yellow screen of death. in the code the image url says that there is no image. :D enter image description here

    enter image description here

  • Craig Mayers 164 posts 508 karma points
    Oct 05, 2017 @ 11:58
    Craig Mayers
    0

    Mikkel,

    Your code syntax is off slightly...

    You are missing a ( on line 20 - where you are setting the caseImageNode.

    Correct this and try again.

  • mikkel 143 posts 365 karma points
    Oct 05, 2017 @ 12:01
    mikkel
    0

    This code here was the one that work for me :) Can you tell mee what went wrong for me :D

    Thanks Alex and Craig for your help

    if (item.HasValue("caseBillede"))
    {
        var caseImageNode = item.GetPropertyValue<IPublishedContent>("caseBillede");
        <img src="@caseImageNode.Url" style="width: 200px" alt="@caseImageNode.GetPropertyValue("alt")"/>
    }
    
  • Craig Mayers 164 posts 508 karma points
    Oct 05, 2017 @ 12:03
    Craig Mayers
    2

    Sytanx Error...

    And as Alex said, my code could have been refactored to 2 lines, as you have done here.

    Glad you sorted it out.

Please Sign in or register to post replies

Write your reply to:

Draft