Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Dec 27, 2011 @ 12:51
    Anthony Candaele
    0

    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 in nodes)
             {
                  
                  <h3><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]&amp;width=150" /@(Library.Truncate(Library.StripHtml(body)300true))</p>
              
                       }
                  else{
                      <p>@(Library.Truncate(Library.StripHtml(body)300true))</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

  • Anthony Dang 1404 posts 2558 karma points MVP 2x c-trib
    Jan 03, 2012 @ 11:12
    Anthony Dang
    0

    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
    See this:

    http://umbraco.com/follow-us/blog-archive/2011/2/24/umbraco-47-razor-feature-walkthrough-%E2%80%93-part-2.aspx

     


  • Anthony Candaele 1197 posts 2049 karma points
    Jan 03, 2012 @ 12:43
    Anthony Candaele
    0

    Hi Anthony,

    I'm glad to report that I solved this issue. 

    @foreach (dynamic in nodes)
                    {
                        dynamic file n.uBlogsyPostImage.mediaItem.NewsImage;                   
                        <li>
                            @if(file.HasValue())
                            {
                            <img src="/[email protected]&amp;width=96&amp;height=96" />
                            }
                            <strong>@n.uBlogsyPostDate.ToString("d MMMM yyyy")</strong>
                            <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

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 03, 2012 @ 12:50
    Anthony Candaele
    0

    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

  • Anthony Dang 1404 posts 2558 karma points MVP 2x c-trib
    Jan 03, 2012 @ 12:53
    Anthony Dang
    0

    You should write a quick blog post about it!

     

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 03, 2012 @ 13:10
    Anthony Candaele
    0

    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:

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies