Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jul 29, 2011 @ 16:26
    Ismail Mayat
    0

    DAMP with dynamic node 4.7.1

    Guys,

    I have property on my doctype which is using DAMP.  I am using macro engines 4.7.1 in umbraco 4.7.  I want to render out the first image in the list so i am trying todo the following:

               var currentNewsNode = Model.NodeById(result.Id);
               <article class="clearfix">
    
                @if (currentNewsNode.images.ToString() != string.Empty)
                {
                     <div class="pic">
                        <a href="@result.FullUrl()"><img src="@currentNewsNode.images.childNode[0].Element("umbracoFile").Value" alt="pic1" /></a>
                    </div>
    
                }

     

    i get error  

    Error loading Razor Script NewsListLandingPage.cshtml'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'childNode'

    am i missing a trick here?

    Regards

    Ismail

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 29, 2011 @ 16:33
    Jeroen Breuer
    0

    Your not using the mediaItem element. Even though you only have 1 item this should be fixed in 4.7.1. See this topic: http://our.umbraco.org/forum/developers/razor/20024-Root-node-removed-problem-in-DynamicXml.

    Perhaps you can use this example: http://our.umbraco.org/forum/developers/razor/18859-Question-for-an-XML-Data-Loop?p=2#comment76855

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 29, 2011 @ 16:40
    Jeroen Breuer
    0

    Can you test if this example works?

    @currentNewsNode.images.mediaElement.Image.umbracoFile

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 29, 2011 @ 16:49
    Jeroen Breuer
    1

    Here's another tip :). Try the Razor DataType Model project for 4.7.1. It has a DAMP model.

    Then I think you could do this (haven't tried it myself yet).

    @currentNewsNode.images.Image()

    Jeroen

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jul 29, 2011 @ 18:07
    Ismail Mayat
    0

    Jeroen,

    I did 

     @if (currentNewsNode.images.ToString() != string.Empty)

                {    

                    var counter = 0;

                    foreach (dynamic imageItem in currentNewsNode.images){

                        if (counter == 0)

                        {

                            <div class="pic">

                                <a href="@result.FullUrl()"><img src="@imageItem.Image.umbracoFile" alt="@imageItem.Image.Description" /></a>

                            </div>

                        }

                        counter++;

                    }

                }

     

    which works will look into that razor datatype model looks very interesting.

    Regards

    Ismail

     

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 01, 2011 @ 09:13
    Jeroen Breuer
    0

    Did you try the sample I used in my second post?

    One of these should work:

    @currentNewsNode.images.mediaElement.Image.umbracoFile
    @currentNewsNode.images.Image.umbracoFile

    If you have multiple items it will still only return the first image because you don't loop through them. It's a lot shorter than your code :).

    Jeroen

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Aug 01, 2011 @ 10:37
    Ismail Mayat
    0

    Jeroen,

    Tried that i get error 

    Error loading Razor Script NewsListLandingPage.cshtml'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'Image'

    And if i use first statement then does not contain mediaElement error. I am storing as full xml. Using 4.7 but macroengines 4.7.1

    Regards


    Ismail

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 01, 2011 @ 10:41
    Jeroen Breuer
    0

    I think you'll still need the if statement. So something like this:

    @if (currentNewsNode.images.ToString() != string.Empty)
    {
    <img src="@currentNewsNode.images.mediaElement.Image.umbracoFile"/>
    //or
    <img src="@currentNewsNode.images.Image.umbracoFile"/>

    Jeroen

  • Murray Roke 503 posts 966 karma points c-trib
    Nov 01, 2011 @ 07:23
    Murray Roke
    0

    ok, here's my version:

    @{ var crop = item.Image.Find("//crop[@name='thumbnail']"); } 
    @if (crop.BaseElement != null && !crop.IsNull()) 
    { 
        <img src="@crop.url" /> 
    }
    

    If anyone has any nice way to tidy up the if condition let me know.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Nov 01, 2011 @ 09:25
    Jeroen Breuer
    0

    If you're using DAMP 2.0 you can use this in Razor for getting a crop:

    @using DigibizAdvancedMediaPicker;

    <img src="@DAMP_Helper.GetImageCropperUrl(Model.videoImage.mediaItem, "sportVideo")"/>

    For more examples you can install the DAMP 2.0 Samples package (works only on 4.7.1 and if you have DAMP 2.0 installed). Here is a video on how to install it: http://www.screenr.com/gz0s.

    You could also have a look at the Cultiv Razor Examples package. This also has some DAMP examples.

    Jeroen

  • Murray Roke 503 posts 966 karma points c-trib
    Nov 01, 2011 @ 10:44
    Murray Roke
    0

    I have some problems with the cultiv example...although very similar to mine, it will bring up this error if the media item has been deleted (and removed from recycle bin)

    'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'url'

    If the image has never been set then then it will render a blank src attribute in the image (broken image)

    My example code deals with both of these scenarios correctly.

    I didn't try the DAMP 2.0 Samples, but a quick glance leads me to believe it will have the same problem.

Please Sign in or register to post replies

Write your reply to:

Draft