OrchardCMS / Orchard

Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform.
https://orchardproject.net
BSD 3-Clause "New" or "Revised" License
2.37k stars 1.12k forks source link

RequestTokens with default value #4995

Open orchardbot opened 9 years ago

orchardbot commented 9 years ago

anoordende created: https://orchard.codeplex.com/workitem/21166

RequestTokens are very powerful when used in conjunction with, for example, custom searches using Queries and Projections.

Problem It fails, however, when a querystring parameter is omitted. Sometimes this can be worked around, but, for example in the case of a number, the decimal parser in Projections chokes on the empty value with a FormatException.

Solution Allow an optional default value to be specified in the token, so that when a QueryString / Form Value is omitted (either only the value or entirely)

Examples Example of specifying a default value (for the example I have used a real-estate search): {Request.QueryString:bedrooms} // No default value {Request.QueryString:bedrooms,1} // A default value of "1"

Examples of querystrings that would work with a default specified: /search?bedrooms=2 // The value "2" is used /search?bedrooms= // The default value is used when specified in token /search // The default value is used when specified in token

orchardbot commented 9 years ago

anoordende commented:

Pull request: 7943

orchardbot commented 9 years ago

@Piedone commented:

Agree, but as a current workaround you could make use of the WrapNotEmpty token.

orchardbot commented 9 years ago

@sebastienros commented:

We talked about it today and we think that the result should be empty in this case: /search?bedrooms=

PR contains the recommended code

orchardbot commented 9 years ago

anoordende commented:

Updated PR, re-applied to latest 1.x source and updated to not override empty query/form parameter values.

anoordende commented 8 years ago

Am just about to breathe new life into this issue with a PR.