3
Vote

Match Url in placement by Regex (Placement extensibility)

description

It does not require a lot of code, but in my opinion it is very useful.

For example I need to show BodyPart only on the first page of the list.

For do this need change BuildPredicate function in Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy.ShapePlacementParsingStrategy class
Add to it
case "PathRegex":
                    return ctx =>
                    {
                        return Regex.IsMatch(VirtualPathUtility.ToAppRelative(
                            HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url.PathAndQuery : ""), 
                            expression, RegexOptions.IgnoreCase) && predicate(ctx);
                    };
And then use
<Match PathRegex="^~/.*\?.*">
In general, it would be useful to be able to create their own rules for handling placement

comments

Piedone wrote Jun 29, 2013 at 6:38 PM

I like the idea. These arguments could be handled by providers, similar to other paces of Orchard, including the ones in the Place element probably. This would add a lot of extensibility to Placement.

sebastienros wrote Jun 29, 2013 at 7:33 PM

True, if there is a switch/case there is place for extensibility. And it would not be a breaking change.

Jetski5822 wrote Jul 1, 2013 at 4:01 PM

+1 Really like the idea.

sebastienros wrote Jul 1, 2013 at 6:12 PM

Just to be sure, I am for making the behavior extensible, not quite for a Regex expression OOB in placement.
This can be done as a module and we try not to use any Regex in sensitive sections.

Jetski5822 wrote Jul 1, 2013 at 11:47 PM

I know what you meant. :)

But I think that we need to review placement.info before doing this kinda thing.