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:
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.
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.
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:
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
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
Can you test if this example works?
Jeroen
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).
Jeroen
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
Did you try the sample I used in my second post?
One of these should work:
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
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
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
ok, here's my version:
If anyone has any nice way to tidy up the if condition let me know.
If you're using DAMP 2.0 you can use this in Razor for getting a crop:
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
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)
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.
is working on a reply...