Copied to clipboard

Flag this post as spam?

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


  • Niklas Hjelm 104 posts 125 karma points
    Nov 15, 2011 @ 16:35
    Niklas Hjelm
    0

    Showing image in search results

    Hi!

    I'm using Umbraco Examine and want to display an image

       @if(node.Fields.Keys.Contains("huvudBild"))
            {
              var image = node.Fields["huvudBild"];

              @image
                    
            }

    Right now I'm using this code which gives me the path to the image but with some numbers at the end causing the url to be wrong. Should mention that I'm also using Damp. Any ideas on how to solve this problem?

    Thanks / Niklas

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Nov 17, 2011 @ 19:41
    Sebastiaan Janssen
    0

    It's because node.Fields is probably XML and the numbers are values in the other elements of your xml.

    Can you tell me what "node" is? Is that something from Examine or is it a proper DynamicNode from Razor?

  • Niklas Hjelm 104 posts 125 karma points
    Nov 17, 2011 @ 20:08
    Niklas Hjelm
    0

    Hi Sebastiaan

    Yes you're right. Had to do a regex and now it works fine :)

     

     

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Nov 17, 2011 @ 20:09
    Sebastiaan Janssen
    0

    A regex! Ouch.. now you have two problems... ;-)

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Nov 17, 2011 @ 20:13
    Sebastiaan Janssen
    0

    By the way, you can solve it in a much more pretty way, take your xml and convert it to dynamicxml and then just query it like you would query the model:

    @{ var field =  Library.ToDynamicXml(node.Fields["huvudBild"]); 
    @field.image 
Please Sign in or register to post replies

Write your reply to:

Draft