Copied to clipboard

Flag this post as spam?

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


  • alimac 182 posts 371 karma points
    Aug 12, 2013 @ 16:36
    alimac
    0

    Using DAMP with the new API?

    Hi,

    I'm trying to use DAMP with umbraco v6 and I'm struggling to find any examples of how DAMP works with the new API? Are there any examples floating about?

    At the moment I'm really struggling with working out how to get the first image in a collection using razor...

    Thanks

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Aug 12, 2013 @ 16:48
    Jeroen Breuer
    0

    Hi,

    The V6 API is about creating content and media. When you mean new API, I think you are talking about MVC Razor views? Those are news since 4.10 and not v6 ;-).

    Have a look at the DAMP Gallery. That shows how you can use DAMP in Razor.

    Jeroen

  • alimac 182 posts 371 karma points
    Aug 12, 2013 @ 16:53
    alimac
    0

    Thanks Jeroen, that page is exactly what I'm looking at right now :-)

    I'm having difficulty retrieving the values though - I've had to configure the data type so it stores the Ids (it's the only way I can get it to work with my installation) yet I can't seem to get any data out.

    Using your example, I've tried this:

    @{ dynamic i = CurrentPage.backgroundImages; }
    <img src="@i[0].umbracoFile" alt=""/>
    

    ..but clearly this isn't working. Am I on the right track? The gallery example doesn't seem to show how to get an image at an index?

    Thanks

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Aug 12, 2013 @ 17:01
    Jeroen Breuer
    101

    Why do you want to get an image by index? Currently you're only getting a csv if you do "dynamic i = CurrentPage.backgroundImages" so "i[0].umbracoFile" also won't work. It's different from dynamic xml in the old Razor macro's. 

    If you have the DAMP Property Editor Value Converter installed you can do this:

    dynamic i = CurrentPage.images;
    <img src="@i.First.Url" alt="@i.First.Alt"/>

    It's better to do it strongly typed.

    So something like this:

    var images = Model.Content.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("images")
    var firstImage = images.First;
    <img src="@firstImage.Url" alt="@firstImage.Alt"/>

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Aug 12, 2013 @ 17:30
  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Aug 14, 2013 @ 09:40
    Jeroen Breuer
    0

    Hello,

    Did any of my examples help you?

    Jeroen

  • andrew shearer 506 posts 652 karma points
    Aug 14, 2013 @ 10:37
    andrew shearer
    0

    ^ we too are using our own extension methods to work with DAMP crops in a standardised manner. It would be great to see DAMP itself have these sorts of helper methods. 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Aug 14, 2013 @ 10:58
    Jeroen Breuer
    0

    That's what the DAMP Property Editor Value Converter is supposed to do, but you can also create your own extension methods if you like.

    Jeroen

  • andrew shearer 506 posts 652 karma points
    Aug 14, 2013 @ 11:02
    andrew shearer
    0

    ok cool, thanks for the info. Thats a separate package from DAMP though, correct? and it also means using 'dynamic' and our preference is for strongly-typed extensions which is why we've rolled our own.

     

  • alimac 182 posts 371 karma points
    Aug 14, 2013 @ 11:06
    alimac
    0

    Hi Jeroen,

    Thanks for all your help - I've got everything working now :-)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Aug 14, 2013 @ 11:06
    Jeroen Breuer
    0

    Yes it's a separate package. You can also use it strongly typed (which I'm doing myself). See this example:

    Single image:

    var images = Model.Content.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("images")
    var firstImage = images.First;
    <img src="@firstImage.Url" alt="@firstImage.Alt"/>

    Multiple images:

    var images = Model.Content.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("images")
    foreach(var image in images)
    {
    <img src="@image.Url" alt="@image.Alt"/>

    Jeroen

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Aug 14, 2013 @ 11:10
    Hendy Racher
    2

    Hi, thought I'd add a little tip - define DAMP as an alias at the top of the file so that the generic type parameter is shorter, and there's no confusion about which Model is Model:

    @using DAMP = DAMP.PropertyEditorValueConverter.Model;
    
    var images = Model.Content.GetPropertyValue<DAMP>("images");
    
  • Anthony Candaele 1197 posts 2049 karma points
    Sep 10, 2013 @ 14:32
    Anthony Candaele
    0

    Hi,

    In installed DAMP 2.5 and DAMP Property Value Converter 1.2 on my Umbraco 6.1.5 website.

    It's my first Umbraco MVC site, so this is a bit new to me.

    I tried to show an image stored with DAMP on my page like this:

    <img alt="Browser-window-2" src="@CurrentPage.section1Image" />

    But the image isn't rendered on the page. When I look in the source code of the page I see this:

    <img alt="Browser-window-2" src="DAMP.PropertyEditorValueConverter.Model">

    What am I doing wrong?

    Thanks for your help,

    Anthony

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Sep 10, 2013 @ 14:37
    Jeroen Breuer
    0

    That's because @CurrentPage.section1Image is of the type DAMP.PropertyEditorValueConverter.Model. If you want to show the url of the first selected image you can try this:

    <img alt="Browser-window-2" src="@CurrentPage.section1Image.First.Url" />

    Jeroen

  • Anthony Candaele 1197 posts 2049 karma points
    Sep 10, 2013 @ 14:42
    Anthony Candaele
    0

    Oh I see,

    Thanks a lot Jeroen. Very convenient this DAMP Property Value Converter : )

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Sep 10, 2013 @ 14:48
  • Anthony Candaele 1197 posts 2049 karma points
    Sep 10, 2013 @ 14:59
    Anthony Candaele
    0

    I pushed the big green download button on this page

    http://our.umbraco.org/projects/backoffice-extensions/damp-property-editor-value-converter

    Which version should I use then? ( the link you gave in your previous post just goes to this forum thread )

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Sep 10, 2013 @ 15:18
    Jeroen Breuer
    1

    You downloaded the correct version, but in your example you use the dynamic features of Umbraco (@CurrentPage) and it's better to use the strongly typed version (@Model.Content). You can read more about it here: http://our.umbraco.org/documentation/Reference/Mvc/querying

    "Some complex queries cannot be written dynamically because the dynamic query parser may not understand precisely what you are coding. There are many edge cases where this occurs and for each one the parser will need to be updated to understand such an edge case. This is one reason why strongly typed querying is much better."

    Jeroen

  • Anthony Candaele 1197 posts 2049 karma points
    Sep 10, 2013 @ 15:43
    Anthony Candaele
    0

    Oh I see, thanks a lot for the tip. As I said, Umbraco MVC is still a bit new to me, but I'm loving it so far.

Please Sign in or register to post replies

Write your reply to:

Draft