Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Nov 05, 2014 @ 21:21
    Steve
    0

    Auto-Update of Media Content

    I have a Razor script that is pulling together documents within multiple folders in the Media Library and displaying those documents as a list of links to the associated document as a macro on the page. As it is now, everytime a document is added or changed in the Media Library folder that is used for the macro, all the previously added documents fail to be pulled into the Macro on the page. Is there a way to assure that the content of these Media Library folders will allways refreshed within the macro? Here is the Razor:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        if ( String.IsNullOrEmpty(@Parameter.mediaFolder) ) {
            <div><p>A folder has not been selected</p></div>
        }
        var folder = Parameter.mediaFolder;
        var media  = Library.MediaById(folder); @* was Model.MediaById(folder);  *@
    }
    @helper traverse(dynamic node) {
        var cc = node.Children;  
        if ( cc.Count()>0 && node.NodeTypeAlias == "Folder" ) {
            <ul>
                @foreach (var c in cc) {
                    <li>
                        @structure(c)
                        @traverse(c)
                    </li>
                }
            </ul>
        }
    }
    @helper structure( dynamic node ){
        if ( node.NodeTypeAlias == "Folder" ) {
            <span class="folder" id="@node.Name.ToLower().Replace(" ", "_")">@node.Name</span>
        } else {
            <a href="@node.Url" target="_blank">@node.Name</a>
        }
    }
    <div class="formWrangler">
        @traverse(media)
    </div>
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Nov 18, 2014 @ 23:41
    Jeavon Leopold
    0

    This sounds like a problem with your Examine index not updating or corrupting as Examine is used a sort of cache for media. The Razor here looks fine.

Please Sign in or register to post replies

Write your reply to:

Draft