I am looking to create a macro that uses the multiple media picker as a parameter. For some reason my marco partial view refuses to see the images in the parameter value. I've set the code to test up as follows:
The way Macro Parameters are 'read' it doesn't go via a Property Value Converter in the same way that reading a property value from a Document Type.
Therefore when you use
Model.MacroParameters["imageSlide"]
all you are able to get is the 'raw' ids of the images that have been picked in the multiple media picker.
But you can turn these into IPublishedContent by using the UmbracoHelper's 'Media' method which accepts an array of Ids and returns an IEnumerable of IPublishedContent.
So something like this might work for you:
//you'll get a csv of the ids
string pickedMediaCsv = Model.MacroParameters["imageSlide"].ToString();
// you can then turn them into an array of ids
string[] pickedMediaIds = String.Split(pickedMediaCsv, new char[]{','}, StringSplitOptions.RemoveEmptyEntries);
//now get the IPublishedContent representation
IEnumerable<IPublishedContent> mediaItems = Umbraco.Media(pickedMediaIds);
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using Umbraco.Web;
@using Umbraco.Web.Composing;
@using Clean.Core.Helpers;
@{
//you'll get a csv of the ids
string pickedMediaCsv = Model.MacroParameters["sliderImage"].ToString();
// you can then turn them into an array of ids
string[] pickedMediaIds = String.Split(pickedMediaCsv, new char[]{','}, StringSplitOptions.RemoveEmptyEntries);
//now get the IPublishedContent representation
IEnumerable<IPublishedContent> mediaItems = Umbraco.Media(pickedMediaIds);
}
@if (mediaItems != null)
{
<ul>
@foreach (var item in mediaItems) {
<li>Test</li>
}
</ul>
}
else{
<p>nope</p>
}
I'm currently getting the following error:
System.Web.HttpCompileException (0x80004005): C:\inetpub\wwwroot\UmbracoTemp\Views\MacroPartials\ImageSliderMacro.cshtml(10): error CS1503: Argument 1: cannot convert from 'string' to 'char'
Multiple Media Picker in Macro Parameter problem
I am looking to create a macro that uses the multiple media picker as a parameter. For some reason my marco partial view refuses to see the images in the parameter value. I've set the code to test up as follows:
I'm not sure how to get the partial to output the test li tags in this example. it always returns the else statement,
Hi Rich W
The way Macro Parameters are 'read' it doesn't go via a Property Value Converter in the same way that reading a property value from a Document Type.
Therefore when you use
Model.MacroParameters["imageSlide"]
all you are able to get is the 'raw' ids of the images that have been picked in the multiple media picker.
But you can turn these into IPublishedContent by using the UmbracoHelper's 'Media' method which accepts an array of Ids and returns an IEnumerable of IPublishedContent.
So something like this might work for you:
Hope that helps!
regards
Marc
Marc,
Thank you. I modified my code as follows:
I'm currently getting the following error:
Any more help would be greatly appreciated.
Sorry Rich
is this any better?
regards
Marc
Marc,
Yes sir, that did the trick.
Thank you very much.
is working on a reply...