Display contents of Multiple Media Picker in macro.
Hi Folks, I'm trying to display a list of documents added to node using the Multiple Media Picker - like a list of downloads.
I've created a macro and associated XLST file base upon something I've found out there:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@if(Model.Content.HasValue("downloadPublicDocuments"))
{
var docsList = Model.Content.GetPropertyValue<string>("downloadPublicDocuments").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
var docsCollection = Umbraco.TypedMedia(docsList).Where(x => x != null);
var count = 0;
var closed = false;
var opener = "<div class='col-sm-6'>";
var closer = "</div>";
foreach (var docItem in docsCollection)
{
if(count == 0)
{
closed = false;
@Html.Raw(opener);
}
var bytes = Convert.ToInt64(docItem.GetPropertyValue("umbracoBytes"));
var inmb = bytes / 1048576;
var inkb = bytes / 1024;
<div class="file">
<h1>@docItem.Name</h1>
<p>File Type: @docItem.GetPropertyValue("umbracoExtension").ToString().ToUpper() | 25 March 2015 | @inkb kb<p>
</div>
if(count == 1)
{
closed = true;
@Html.Raw(closer);
count = 0;
}
else
{
count++;
}
}
if(!closed)
{
closed = true;
@Html.Raw(closer);
}
}
The page returns no documents even though I've attached them to the node. Is there an easier was of listing the media attached to a node? Any help will be greatly appreciated.
With a bit of tweaking based on what you suggested and what I've already done - managed to get this Partial View Macro working. Basically, it lists media, file type, size and date - ideal for download pages if anyone is interested!
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@if (CurrentPage.HasValue("caseStudyImages"))
{
var docsList = Model.Content.GetPropertyValue
Display contents of Multiple Media Picker in macro.
Hi Folks, I'm trying to display a list of documents added to node using the Multiple Media Picker - like a list of downloads.
I've created a macro and associated XLST file base upon something I've found out there:
The page returns no documents even though I've attached them to the node. Is there an easier was of listing the media attached to a node? Any help will be greatly appreciated.
Thanks in advance. Darren
Hi Darren,
Since you are using Umbraco 7, then you will need to use Razor. You could use a partial views or partial view macros.
Try to see this documentation about how to get data from a multiple media picker. https://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/built-in-property-editors-v7/Media-Picker
Hope this helps,
/Dennis
Thanks Dennis, I'll give this a try. Darren
Hi Dennis,
With a bit of tweaking based on what you suggested and what I've already done - managed to get this Partial View Macro working. Basically, it lists media, file type, size and date - ideal for download pages if anyone is interested!
@if (CurrentPage.HasValue("caseStudyImages")) { var docsList = Model.Content.GetPropertyValue
Cheers
Darren
is working on a reply...