Copied to clipboard

Flag this post as spam?

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


  • Joao 53 posts 172 karma points
    Oct 03, 2013 @ 17:59
    Joao
    0

    Picked a node with Content picker and now can't display an image

    Hi!

    So here's my problem. I have a content picker and I want to extract the info in the node. I have successfully extracted the string data but I'm having trouble getting the image. Here is the code:

    @{var pubHigh = @Model.publicationHighlight;
      var newHigh = @Model.newsletterHighlight;}
    <div class="publication">
          <div class="pubimage"><img src="@Model.MediaById(pubHigh).publicationImage.UmbracoFile" alt="publication image"/></div>
    <div class="pubname">@Model.NodeById(pubHigh).nameOfPublication</div>
    <div class="pubdescrip">@Model.NodeById(pubHigh).publicationDescription</div>
    </div>

     What i get is a <img> tag with an empty source. I'm quite lost on how to acess the image. Any thoughts?

     

    Thank you for reading.

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 04, 2013 @ 07:18
    Fuji Kusaka
    100

    Hi Joao,

    Looks like you are using an Upload field for that particular image from the node you picked.

    Try doing something like

    var pubHigh = @Model.publicationHighlight;
    if(Model.HasValue("publicationHightLight")){
    var y = @Model.NodeById(pubHigh);
    <img src="@y.doctypeAlias" alt="publication image">
    }
  • Joao 53 posts 172 karma points
    Oct 07, 2013 @ 12:02
    Joao
    0

    Hi Fuji,

    I tried your solution but I get an error loading the script. If i remove the if clause and just go with: 

    @{var y = @Model.NodeById(pubHigh);}
    <img src="@y.doctypeAlias" alt="publication image"> 

    it does not produce an error but I get a blank image again. 

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 07, 2013 @ 12:04
    Fuji Kusaka
    0

    you need to change this part and replace the doctypeAlias with the one you are using.

    <img src="@y.doctypeAlias" alt="publication image"> 
  • Joao 53 posts 172 karma points
    Oct 07, 2013 @ 12:31
    Joao
    0

    Oh god, that flew right through me!

     

    I got it working now:

     

    var y = @Model.NodeById(pubHigh);
    <img src="@Model.MediaById(@y.publicationImage).UmbracoFile" alt="publication"/>
    

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 07, 2013 @ 12:44
    Fuji Kusaka
    0

    However i would keep the if statement in the case my upload field is not a mandatory field just to avoid any error when rendering the code. :)

    //fuji

  • 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