Copied to clipboard

Flag this post as spam?

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


  • SlothMonkey 17 posts 56 karma points
    Jan 26, 2015 @ 13:22
    SlothMonkey
    0

    Finding out if media has been updated

    I'm creating a list that brings back a list of the recently updated pages on my site. When a page is created modified, it auto adds it to the list.

    Now I'm wanting to do the same but to also include media as well.

    How can I modify my code to allow this. I'm very new to umbraco still.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        var root = CurrentPage.AncestorOrSelf(1);
    }
    
    @*Recent Updates widget: Gets 3 last updated nodes*@
    
    <h3>Recent Updates</h3>
    
    <ul>
        @foreach (var item in root.Descendants().OrderBy("updateDate desc").Take(3))
        {
            <li>
                @item.lastEdited
    
                <a href="@item.Url">@item.Name</a><br />
                Updated: @item.updateDate.ToString("HH:mm") on @item.updateDate.ToString("dd MMM yyyy")
            </li>
        }
    </ul>
    
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jan 26, 2015 @ 21:30
    Dennis Aaen
    0

    Hi SlothMonkey,

    For the media you can use the built in code-snippet called List Images From Media Folder, then the user can pick a media folder in the media section, and then you loop through the images in this folder.

    You can do it using a partial view macro, then when you add the macro to the template, and pick the folder in media section

    For the Partial view macros, you need code like this, and add a paramerter to your macro. http://umbraco.tv/videos/implementor/working-with-umbraco-data/macros/setting-up-macro-parameters/ to see this video, it require that you have access to the Umbraco TV.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @*
        Macro Parameters To Create, for this macro to work:
        Alias:mediaId     Name:Media Folder ID    Type:Single Media Picker
    *@

    @if (Model.MacroParameters["mediaId"] != null)
    {
         @* Get the media folder as a dynamic node *@
        var mediaFolder = Umbraco.Media(Model.MacroParameters["mediaId"]);
       
        if (mediaFolder.Children.Any())
        {
            <ul>
                @* for each item in children of the selected media folder *@
                @foreach (var mediaItem in mediaFolder.Children.Take(3))
                {
                    <li>
                        <a href="@mediaItem.Url"><img src="@mediaItem.umbracoFile" alt="@mediaItem.Name" /></a>
                    </li>
                    <p>test:@mediaItem.lastEdited</p>
                    <p>updated @mediaItem.updateDate.ToString("HH:mm") on @mediaItem.updateDate.ToString("dd MMM yyyy")</p>

                }
            </ul>
        }
    }

    Partial view macro documentation can be found here: http://our.umbraco.org/documentation/Reference/Templating/Macros/Partial-View-Macros/

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft