I have got a macro with a multiple media picker as a parameter, I am trying to get the values and use them in razor macro but I am not getting any values,
This is the source code showing the macro parameters with value DocumentsFolder is my parameter name.
I think that you should be good with the code snippet below. Remember to add the macro parameter to the macro, so the user can choose the folders. And you will need to click the add bottom in there, else is not set.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
Macro to display a gallery of images from media the media section.
Works with either a 'Single Media Picker' or a 'Multiple Media Picker' macro parameter (see below).
How it works:
- Confirm the macro parameter has been passed in with a value
- Loop through all the media Id's passed in (might be a single item, might be many)
- Display any individual images, as well as any folders of images
Macro Parameters To Create, for this macro to work:
Alias:mediaIds Name:Select folders and/or images Type: Multiple Media Picker
Type: (note: you can use a Single Media Picker if that's more appropriate to your needs)
*@
@{ var mediaIds = Model.MacroParameters["mediaIds"]; }
@if (mediaIds != null)
{
<ul class="thumbnails">
@foreach (var mediaId in mediaIds.ToString().Split(','))
{
var media = Umbraco.Media(mediaId);
@* a single image *@
if (media.DocumentTypeAlias == "Image")
{
@Render(media);
}
@* a folder with images under it *@
if (media.Children("Image").Any())
{
foreach (var image in media.Children("Image"))
{
@Render(image);
}
}
}
</ul>
}
@helper Render(dynamic item)
{
<li class="span2">
<a href="@item.umbracoFile" class="thumbnail">
<img src="@item.umbracoFile" alt="@item.Name" />
</a>
</li>
}
Multiple Media Picker as a macro parameter
Hi
I have got a macro with a multiple media picker as a parameter, I am trying to get the values and use them in razor macro but I am not getting any values,
This is the source code showing the macro parameters with value DocumentsFolder is my parameter name.
<div class="umb-macro-holder ListAllFiles mceNonEditable umb-macro-mce_0"><!-- <?UMBRACO_MACRO macroAlias="ListAllFiles" DocumentsFolder="1069,1070" /> --><ins>
This is the line in my code that I am expecting to return a string with a value of "1069, 1070")
var bannerListValue2 = Umbraco.Content(Model.MacroParameters["DocumentsFolder"]);
unfortunately my bannerListValue2 is empty
any help much appreciated
thanks
Bal
Hi Bal,
I think that you should be good with the code snippet below. Remember to add the macro parameter to the macro, so the user can choose the folders. And you will need to click the add bottom in there, else is not set.
Hope this helps,
/Dennis
Thats great thanks Dennis that worked a treat
Bal
is working on a reply...