Design and CSS styles
Version 7.x > Design and CSS styles > Conditional layout based on querystring parameter View modes: 
User avatar
Member
Member
rlull - 11/25/2013 3:55:38 PM
   
Conditional layout based on querystring parameter
I'm trying to show/hide a conditional layout section based on a querystring parameter but can't quite get the syntax right. For example:

<cms:CMSConditionalLayout runat="server" id="ltS" Visible='<%# (QueryString.DCI == "5")) %>'>

I keep getting an "error loading layout" when trying to view the template in Design mode. Anyone know the proper syntax or a better approach?

User avatar
Member
Member
rlull - 11/25/2013 4:58:06 PM
   
RE:Conditional layout based on querystring parameter
Solved with the followiing: <cms:CMSConditionalLayout runat="server" id="ltS" Visible='<%# Equals(Request.QueryString["DCI"], "5") %>'>

User avatar
Member
Member
rlull - 11/25/2013 5:17:05 PM
   
RE:Conditional layout based on querystring parameter
An interesting item I discovered is that NotEquals does NOT work like you would expect based on the documentation. You must use an exclamation mark to achieve this as follows: <cms:CMSConditionalLayout runat="server" id="cl2" Visible='<%# !Equals(Request.QueryString["DCI"], "5") %>'>

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 11/26/2013 4:50:46 AM
   
RE:Conditional layout based on querystring parameter
Hi,

Thank you for your message and for sharing your solution.

However when using NotEquals the macro should compare the first pamareter (query string in your case) and second parameter (5) and return true only if they are different. How did it work in your case?

Kind regards,
Richard Sustek

User avatar
Member
Member
rlull - 11/26/2013 9:52:12 AM
   
RE:Conditional layout based on querystring parameter
Yes, that's what I expected to happen. However, if I use the following code in the Layout on the template, when I switch to the Design tab, I see the following error.

<cms:CMSConditionalLayout runat="server" id="cl2" Visible='<%# NotEquals(Request.QueryString["DCI"], "5") %>'>
<cms:CMSWebPartZone ZoneID="zoneArticles" runat="server" />
</cms:CMSConditionalLayout>

[Error loading the layout]
http://server/CMSVirtualFiles/Templates/Shared/=vg=a705a120-263e-4931-afc4-36ef96ec985a/Resources-Listing_1.ascx(9): error CS0103: The name 'NotEquals' does not exist in the current context

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 11/28/2013 3:28:52 AM
   
RE:Conditional layout based on querystring parameter
Hi,

You are correct, it seems that the system does not even recognize the macro method "NotEquals", I'll submit this to our developers as a bug. Thank you vey much for letting us know so that we can improve Kentico :-)

I will post here when I hear any info from our developers.

Kind regards,
Richard Sustek

User avatar
Member
Member
rlull - 12/6/2013 11:42:34 AM
   
RE:Conditional layout based on querystring parameter
Great, thanks.

User avatar
Certified Developer 8
Certified Developer 8
liquidmagic - 3/5/2014 4:29:04 PM
   
RE:Conditional layout based on querystring parameter
Hello,

has this been fixed on any new releases?

Thank you,
Dimitris

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 3/6/2014 1:45:02 AM
   
RE:Conditional layout based on querystring parameter
Hi,

I have submited the bug in the past and the response of developers is that this is not really a bug. This is not a macro, its a standard C# code and this method is not implemented so that is the reason why it doesnt work. You could create the CMSAbstractTransformation method which could do this, but its unnecessary as you can use

!Equals


Thank you and kind regards,
Richard Sustek