Copied to clipboard

Flag this post as spam?

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


  • Barry Fogarty 493 posts 1129 karma points
    Oct 14, 2013 @ 09:34
    Barry Fogarty
    0

    DAMP recursive properties with Value Converter

    When I run the following line:

    var dampModel = node.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>(propertyAlias, recursive, null);

    it works fine when recursive = false, it returns a DAMP model object, but when on a child document with recursive = true, it returns null.

    Is it because of this Umbraco issue?   Is there a workaround that still returns a DAMP.PropertyEditorValueConverter.Model?

  • Jeroen Breuer 4861 posts 12136 karma points MVP 3x admin c-trib
    Oct 14, 2013 @ 09:40
    Jeroen Breuer
    101

    Hello,

    Yes it's related to that Umbraco issue. Currently the only workaround is to first find the node you are looking for and do .GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>(propertyAlias) on that. 

    Jeroen

  • Barry Fogarty 493 posts 1129 karma points
    Oct 14, 2013 @ 10:23
    Barry Fogarty
    0

    Thanks for the quick reply Jeroen.

    Is there a DAMP helper like Umbraco.TypedMedia?  In my case it made more sense to do

                var imageId = node.GetPropertyValue<string>(propertyAlias, recursive, null)

    and cast it to a media item as follows

                var image = new UmbracoHelper(UmbracoContext.Current).TypedMedia(imageId);

    In this situation I did not need crops but would be nice to cast to be able to cast to a DAMP object from a media ID.

  • Barry Fogarty 493 posts 1129 karma points
    Oct 14, 2013 @ 11:48
    Barry Fogarty
    0

    Just to follow up, there was one snag with my code above . I needed to cast the imageId to an int first, to prevent the DAMP property editor value converter from running:

    var imageId = node.GetPropertyValue(propertyAlias, recursive, 0);

    Only then would the TypedMedia call work.

  • Ali Sheikh Taheri 470 posts 1647 karma points c-trib
    Apr 10, 2014 @ 17:54
    Ali Sheikh Taheri
    0

    Hi Jeroen,

    do you know how can I convert Dynamic XML to Damp Model? (using umbraco 6.1.5)

    the problem is when I do this page.GetPropertyValue("image",true,null) it returns an object which is dynamic xml and now I need to convert it do damp model?

    Cheers

    Ali

  • Jeroen Breuer 4861 posts 12136 karma points MVP 3x admin c-trib
    Apr 10, 2014 @ 17:59
    Jeroen Breuer
    0

    Hello,

    I need some more code to see how it currently works before I can help you. Can you paste the page where you are using that part?

    Jeroen

  • Ali Sheikh Taheri 470 posts 1647 karma points c-trib
    Apr 10, 2014 @ 18:20
    Ali Sheikh Taheri
    0

    the problem is this http://issues.umbraco.org/issue/U4-1958.

    so I cannot use GetPropertyValue<DampModel>("image", true, null)

    and in your comment above you mentioned that

    "Currently the only workaround is to first find the node you are looking for and do .GetPropertyValue

    my question is how to get that node?

    the only way I know is to do CurrentPage.GetPropertyValue("image",true) but this returns dynamic XML of the image :

    <DAMP><mediaItem><Image id="3694" version="b4c57f37-b833-44e0-b2f2-14f83bec3005" parentID="1078" level="2" writerID="0" nodeType="1032" template="0" sortOrder="30" createDate="2014-03-24T14:18:28" updateDate="2014-03-26T11:50:58" nodeName="header-right-hand" urlName="header-right-hand" writerName="abv" nodeTypeAlias="Image" path="-1,1078,3694">
                    <umbracoFile>/media/1202/header-right-hand.jpg</umbracoFile>
                    <umbracoWidth>1120</umbracoWidth>
                    <umbracoHeight>480</umbracoHeight>
                    <umbracoBytes>197676</umbracoBytes>
                    <umbracoExtension>jpg</umbracoExtension>
                    <altText />
                  </Image>
                </mediaItem></DAMP>
    

    so the quesiton is how to convert this into DampItem or DAMP.PropertyEditorValueConverter.Model

    I hope this makes sense. I dont have much code to paste here than above.

  • Jeavon Leopold 3008 posts 13216 karma points MVP 7x admin c-trib
    Apr 10, 2014 @ 18:56
    Jeavon Leopold
    1

    Two solutions for you:

    1. Upgrade to Umbraco 6.2RC or 7
    2. Do something like the below:

    Snippet

    @{
        var mapImage = Model.Content.AncestorsOrSelf().Where(x => x.HasProperty("mapImage") && x.HasValue("mapImage")).FirstOrDefault();
        if (mapImage != null){
    
            <div class="maplink-map" style="background-image: url(@(mapImage.GetPropertyValue<DampModel>("mapImage").First.Url))"> </div>
        }
    }
    
  • Ali Sheikh Taheri 470 posts 1647 karma points c-trib
    Apr 10, 2014 @ 19:02
    Ali Sheikh Taheri
    0

    thank you so much Jeavon, the snippet is exactly what I needed

    Cheers

    Ali

Please Sign in or register to post replies

Write your reply to:

Draft