Hide a Part by Path Template

Topics: Customizing Orchard, Writing modules
Jun 29, 2013 at 12:56 PM
Edited Jun 29, 2013 at 12:57 PM
I would like to hide a Part and a Field if url contains '?' symbol.
Example, if url like this:
  1. ~/my-url-21?page=2
  2. ~/my-url-99?query-param=3
How can i do this?
Jun 29, 2013 at 4:02 PM
Edited Jun 29, 2013 at 4:03 PM
For do this:
  1. Copy Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy.ShapePlacementParsingStrategy to your module.
  2. Change namespase
  3. Add [OrchardSuppressDependency("Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy.ShapePlacementParsingStrategy")] attribute to new class
  4. Add to BuildPredicate function
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 can be use placement info for it.

Example:
<Match PathRegex="^~/.*\?.*">