Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple recursive media folder/file viewer macro for directory browsing in #Umbraco 7+, using Bootstrap 3 for display. Not suitable for >100 files (use a surfacecontroller)
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{ var mediaId = Model.MacroParameters["mediaId"]; }
@helper DisplayFolder(dynamic folder, bool collapsed) {
var items = folder.Children().OrderBy("DocumentTypeAlias Desc,Name");
if (items.Any()) {
<a class="list-group-item" role="button" aria-expanded="false" data-toggle="collapse" href="#macro-mediaList-folder-@folder.Id">
<i class="glyphicon glyphicon-folder-open"></i> &nbsp; @folder.Name
</a>
<div class="list-group @(collapsed?"collapse":"collapse in") well well-sm" id="macro-mediaList-folder-@folder.Id">
@foreach(var item in items) {
if(item.DocumentTypeAlias=="Folder") {
@DisplayFolder(item, true)
} else {
<a href="@item.Url" class="list-group-item">
<i class="glyphicon glyphicon-file"></i> &nbsp; @item.Name
</a>
}
}
</div>
}
}
@if (mediaId != null)
{
var media = Umbraco.Media(mediaId);
<div class="list-group">
@DisplayFolder(media, false)
</div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment