Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Filter Media Gallery Folder Based On Parameter View modes: 
User avatar
Member
Member
olevin-merlenorman - 1/15/2010 2:28:10 PM
   
Filter Media Gallery Folder Based On Parameter
I have a media library with multiple folders. There will be one page where the user can browse all of the folders. But on certain pages the user will only see one folder.

I thought I could create a Page Template that has the media gallery web part in it and set the web part to filter based on a query string parameter from the url to determine which media library folder to show.

Example:

~/EducationDownloads.aspx?path=education - This will only show the media files in the education folder
~/AdvertisingDownloads.aspx?path=advertising - This will only show the media files in the advertising folder

However, I can't figure out how to add query string parameters to the url of the page so that when the user clicks on the link from the menu it will go to: ~/AdvertisingDownloads.aspx?path=advertising

How do I add query string parameters to a menu item's url?

The only other way that I saw to specify which media folder to show is to create an ad hoc template for each folder and specify the path in the web part settings. But I don't want to manage 10+ ad-hoc templates for this purpose.

Is there a better way?

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 1/18/2010 2:57:36 PM
   
RE:Filter Media Gallery Folder Based On Parameter
Hi,

Unfortunately, default menu web parts/controls are not designed to enable users to add query strings parameters to page URL. You can create your own menu web part (http://devnet.kentico.com/docs/devguide/developing_web_parts.htm) which will be able to create links to your pages with query strings parameters.

The only way you could change the generated html code of menu web parts (without source code version of Kentico CMS) is to change RenderedHTML property for example of CMS List Menu control:

http://devnet.kentico.com/docs/controls/cmslistmenu.htm

RenderedHTML - Allows you to get or set the HTML code rendered by the control. You need to set this property before the Render event - e.g. in the OnLoad event.

Best regards,
Miroslav Remias.

User avatar
Member
Member
olevin-merlenorman - 1/19/2010 6:03:01 PM
   
RE:Filter Media Gallery Folder Based On Parameter
For the sake of the public I will post Miroslav's suggestion and my solution.

I decided not to add a parameter by changing the RenderedHTML property.

Miroslav had another suggestion:

Ok, the only other solution with I’m aware is to store your additional information not in the URL as query string, but in data of your document. You can create custom field for your document type and fill such information for each document. In code behind of your web part/template you can access the current document information using following example code:

CMS.CMSHelper.CMSContext.CurrentDocument.GetValue("CustomDocumentTypeFieldName")

And you can dynamically set your web part parameters in code behind of your web part/template according to data from current document. I’m not aware of any other solution here.

I went with her solution.

I created a new document type with the parent type set to the Page (Menu Item) and I added a custom attribute called MediaGalleryPath to be used for the MediaLibraryPath on the MediaGallery web part.

I then followed the directions from the documentation here to dynamically set the MediaLibraryPath property on the web part. Here is the code:

protected void Page_Init(object sender, EventArgs e)
{
//Check if the document has the media gallery path as a custom field
if (CMS.CMSHelper.CMSContext.CurrentDocument.ContainsColumn("MediaGalleryPath"))
{
//Set the media gallery's folder to the folder path in the custom field.
this.MediaGalleryControl.MediaLibraryPath = CMS.CMSHelper.CMSContext.CurrentDocument.GetValue("MediaGalleryPath").ToString();

//Reload control with dynamically set properties (required)
this.MediaGalleryControl.ReloadData();
}
}

So now the user can create a new Page with my new document type and set the MediaGalleryPath field in CMS Desk and the correct Media Library Folder will be displayed.

I hope this helps others.

Oran

User avatar
Member
Member
gstaylor-sfopera - 1/25/2011 3:13:00 PM
   
RE:Filter Media Gallery Folder Based On Parameter
This is exactly how I had to implement a similar requirement for our press photo gallery.