Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Webpart visible depending on querystring View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
Nathoushka - 1/7/2011 2:29:34 PM
   
Webpart visible depending on querystring
Hi,

I would like to know if it is possible to hide/show a WebPart depending on the querystring of the page. I have 2 pages with the same name, one for the list, one for the detail, so I thought about putting them together. However, I don't know if it's possible to do that in Portal Engine.

For example:

"http://site.com/myPage.aspx" shows Webpart1 and Webpart2 (list)
"http://site.com/myPage.aspx?id=1" shows Webpart 3 (detail)
"http://site.com/myPage.aspx?id=invalidID" show Webpart1 and Webpart2 (list) + Webpart4 (error message)

Is it possible? I can't seems to find how to do that.

User avatar
Kentico Support
Kentico Support
kentico_radekm - 1/10/2011 2:11:15 AM
   
RE:Webpart visible depending on querystring
Hello.

Regrettably, you can´t use query macro in web part properties (http://devnet.kentico.com/docs/devguide/appendix_a___macro_expressions.htm), therefore the easiest way would be to create and call custom macro within "Visible " property of given web part. Within this macro´s code, you can get query string parameter´s value (CMS.GlobalHelper.UrlHelper.GetUrlParameter method) and return true / false value according to it.

Best Regards,
Radek Macalik

User avatar
Certified Developer v7
Certified  Developer v7
Nathoushka - 1/10/2011 10:48:51 AM
   
RE:Webpart visible depending on querystring
kentico_radekm wrote: Hello.

Regrettably, you can´t use query macro in web part properties (http://devnet.kentico.com/docs/devguide/appendix_a___macro_expressions.htm), therefore the easiest way would be to create and call custom macro within "Visible " property of given web part. Within this macro´s code, you can get query string parameter´s value (CMS.GlobalHelper.UrlHelper.GetUrlParameter method) and return true / false value according to it.

Best Regards,
Radek Macalik


I've started working on that but I have a question. In a custom macro, all I can return is a string, so how to return a bool for a true/false value?

User avatar
Kentico Support
Kentico Support
kentico_radekm - 1/23/2011 2:17:28 PM
   
RE:Webpart visible depending on querystring
Hello.

You do not need to return bool variable, string value (true/false) is enough.

Web parts can handle it and will show / hide themselves according to this (even) string value.

Best Regards,
Radek Macalik