Skip to content

Instantly share code, notes, and snippets.

@alirobe
Last active August 19, 2022 21:49
Show Gist options
  • Save alirobe/2a0d27ad7da455710bc8 to your computer and use it in GitHub Desktop.
Save alirobe/2a0d27ad7da455710bc8 to your computer and use it in GitHub Desktop.
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="#[email protected]">
<i class="glyphicon glyphicon-folder-open"></i> &nbsp; @folder.Name
</a>
<div class="list-group @(collapsed?"collapse":"collapse in") well well-sm" id="[email protected]">
@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