Filtering by Media Properties in Partial View Macro
Hi All
I have created a Partial View Macro that is displayed via the RTE which basically displays items that's are listed in which ever folder you specify.
I have also added another property to Media items 'File' which is called location and each media item is tagged as being relevant one or more location(s).
I would like to filter the Partial View macro to display items by location, I.e, display documents relevant to Company A in one div, Company B in another div etc whilst only having to insert the macro once in the RTE
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
Macro Parameters To Create, for this macro to work:
Alias:mediaId Name:Media Folder ID Type:Single Media Picker
*@
@if (Model.MacroParameters["mediaId"] != null)
{
@* Get the media folder as a dynamic node *@
var mediaFolder = Umbraco.Media(Model.MacroParameters["mediaId"]);
if (mediaFolder.Children.Any())
{
<div class="docContainer">
<div class="docHeader"><h4>Company A</h4></div>
<ul class="docList">
@* for each item in children of the selected media folder *@
@foreach (var mediaItem in mediaFolder.Children)
{
<li>
<a target="_blank" href="@mediaItem.umbracoFile" style="text-decoration:none;"> <img src="~/Images/doc_icon.png" alt="QWERTY" /> @mediaItem.Name</a>
</li>
}
</ul>
</div>
}}
Is what I am trying to do possible and more importantly does it make sense?
Change var mediaFolder = Umbraco.Media(Model.MacroParameters["mediaId"]);
to
var mediaFolder = Umbraco.TypedMedia(Model.MacroParameters["mediaId"]);
This will give you back an IPublishedContent. Enumerating the children of the IPublishedContent will give you another IPublishedContent and you can query its properties like you would do with a contentNode. mediaItem.GetPropertyValue("thePropertyNameOfYourLocations")
Filtering by Media Properties in Partial View Macro
Hi All
I have created a Partial View Macro that is displayed via the RTE which basically displays items that's are listed in which ever folder you specify.
I have also added another property to Media items 'File' which is called location and each media item is tagged as being relevant one or more location(s).
I would like to filter the Partial View macro to display items by location, I.e, display documents relevant to Company A in one div, Company B in another div etc whilst only having to insert the macro once in the RTE
Is what I am trying to do possible and more importantly does it make sense?
Thanks
Ben
Hey BEWD
Change
var mediaFolder = Umbraco.Media(Model.MacroParameters["mediaId"]);
tovar mediaFolder = Umbraco.TypedMedia(Model.MacroParameters["mediaId"]);
This will give you back an IPublishedContent. Enumerating the children of the IPublishedContent will give you another IPublishedContent and you can query its properties like you would do with a contentNode.
mediaItem.GetPropertyValue("thePropertyNameOfYourLocations")
Hope this helps you along.
is working on a reply...