Oh, Jeroen Breuer also pointed to me that is is not neccessary to use the .Media since a datatype of Digibiz Advanced Media Picker type returns the full xml of the media item, so this will do to get the media item:
n.uBlogsyPostImage.mediaItem.NewsImage;
So I'm glad I succeeded in combining uBlogsy with DAMP, to great Umbraco packages :)
extending uBlogsyListPosts.cshtml with image
Hi,
I'm trying to exend the uBlogsyListPosts.cshtml so that every post excerpt has an image.
I added images to my post using the Digibiz Advanced Media Picker and one can add an image using this razor syntac:
dynamic file = @Model.myPropertyAlias.mediaItem.PropertyName;
so I extended the uBlogsyListPosts.cshtml like this:
@foreach (DynamicNode n in nodes)
{
<h3><a href="@n.Url" title='@n.GetProperty("uBlogsyContentTitle").Value'>@n.GetProperty("uBlogsyContentTitle").Value</a></h3>
var body = @n.GetProperty("uBlogsyContentBody").Value;
if (n.HasValue("uBlogsyPostImage"))
{
dynamic file = @Model.uBlogsyPostImage.mediaItem.NewsImage;
<p><img src="/[email protected]&width=150" /> @(Library.Truncate(Library.StripHtml(body), 300, true))</p>
}
else{
<p>@(Library.Truncate(Library.StripHtml(body), 300, true))</p>
}
}
naturally this is not working, so I changed my code to acces the image like this:
dynamic file = @n.GetProperty("uBlogsyPostImage").Value;
But this isn't working either, so I'm a bit stuck here.
Any help would be greatly appreciated
greetings,
Anthony
From your code it looks like you have a property with alias uBlogsyPostImage. I assume this should have an id to the media item you want to display.
Try outputting just
@n.GetProperty("uBlogsyPostImage").Value;
If that works then try getting the media item from that id.
dynamic mediaItem = new DynamicMedia(int.Parse(n.GetProperty("uBlogsyPostImage").Value));
@mediaItem.umbracoFile
http://umbraco.com/follow-us/blog-archive/2011/2/24/umbraco-47-razor-feature-walkthrough-%E2%80%93-part-2.aspx
Hi Anthony,
I'm glad to report that I solved this issue.
@foreach (dynamic n in nodes)
{
dynamic file = n.uBlogsyPostImage.mediaItem.NewsImage;
<li>
@if(file.HasValue())
{
<img src="/[email protected]&width=96&height=96" />
}
<strong>@n.uBlogsyPostDate.ToString("d MMMM yyyy")</strong>
<a href="@n.Url">
@n.uBlogsyContentTitle
</a>
</li>
}
The problem was solved when I changed the DynamicNode argument in the @foreach loopk to 'dynamic'. This is the result:
Thanks for your help,
Anthony
Oh, Jeroen Breuer also pointed to me that is is not neccessary to use the .Media since a datatype of Digibiz Advanced Media Picker type returns the full xml of the media item, so this will do to get the media item:
n.uBlogsyPostImage.mediaItem.NewsImage;
So I'm glad I succeeded in combining uBlogsy with DAMP, to great Umbraco packages :)
greetings,
Anthony
You should write a quick blog post about it!
yeah, good idea!
I customized the following things with uBlogsy:
- I made the uBlogsyListPosts.cshtml read the first 300 characters of a post.
- I added a uBlogsyPostImage using DAMP to the uBlogsyPost documenttype
The result can be seen in this screenshot:
is working on a reply...