Last active
August 19, 2022 21:49
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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> @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> @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