-
-
Save biapar/efc1279c219b5f6405b0184570deb012 to your computer and use it in GitHub Desktop.
Umbraco Macro file to render a list of documents on a page
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 | |
@using Umbraco.Web.Models | |
@{ | |
var folders = Model.GetParameterValue<string>("mediaFolder", "") | |
.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); | |
var subFolders = Model.GetParameterValue<bool>("subFolders", true); | |
var selection = Umbraco.TypedMedia(folders).Where(x => x != null); | |
} | |
@if (selection.Any()) | |
{ | |
int n = 0; | |
<div class="media-library" id="media-library"> | |
@foreach (var mediaNode in selection) | |
{ | |
n++; | |
<div class="media-listing"> | |
@RenderMediaFolder(mediaNode, n, subFolders) | |
</div> | |
} | |
</div> | |
} | |
@helper RenderMediaFolder(IPublishedContent folder, int count, bool subFolders) | |
{ | |
if ( count > 1 ) | |
{ | |
<div class="page-header"> | |
<a data-toggle="collapse" data-parent="#media-library" href="#listing-@count" aria-expanded="true" aria-controls="listing-@count"> | |
<h3>@folder.GetPropertyValue("title", folder.Name)</h3> | |
</a> | |
</div> | |
} | |
var subCount = 0; | |
<div id="listing-@count" class="collapse @Umbraco.If(count==1, "in", "")"> | |
<ul class=" media-item-list list-unstyled"> | |
@foreach (var item in folder.Children.Where(x => x.IsVisible())) | |
{ | |
var itemUrl = item.GetPropertyValue<string>("umbracoFile"); | |
var itemName = item.GetPropertyValue<string>("title", item.Name); | |
var itemType = "unknown"; | |
if (!string.IsNullOrWhiteSpace(itemUrl)) | |
{ | |
itemType = System.IO.Path.GetExtension(itemUrl).Trim('.'); | |
} | |
if (item.DocumentTypeAlias == "Folder") | |
{ | |
if ( subFolders ) | |
{ | |
subCount = subCount + 1; | |
<!-- child folder --> | |
<li class="media-item-folder"> | |
@RenderMediaFolder(item, count+100+subCount, subFolders) | |
</li> | |
} | |
} | |
else | |
{ | |
<li class="media-item-item media-@itemType"> | |
<a href="@itemUrl" target="_blank"> | |
<h4> | |
@itemName <small><span class="glyphicon glyphicon-file" aria-hidden="true"></span></small></h4> | |
</a> | |
<p>@item.GetPropertyValue("summary")</p> | |
</li> | |
} | |
} | |
</ul> | |
</div> | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment