Display Rules and Conditional Rendering
WebComponents can specify when they should appear using display rules. Each WebComponent can have multiple display rules, and if ANY rule matches, the component is shown.
Within a single display rule, there are three matcher lists that work together with AND logic:
displayRules:
# Rule 1: Show in navigation context for users with specific roles
- allOf:
- contextName: navigation
anyOf:
- role: user
- role: admin
noneOf:
- path: "^/public/.*"
# Rule 2: Show in drawer context on specific paths
- allOf:
- contextName: drawer
- path: "^/dashboard/.*"
How Display Rules Are Evaluated
The controller evaluates display rules using this logic:
For each display rule (OR between rules):
- ALL of
allOfmatchers must match (AND logic) - At least ONE of
anyOfmatchers must match (OR logic) - ifanyOfis present - NONE of
noneOfmatchers can match (NOT logic)
If all three conditions are satisfied, that display rule matches and the component is included.
Matcher Types
Each matcher can check three properties:
1. Context Name - Where the polyfea-context element is located
2. Path - URL path as a regular expression
3. Role - User role from HTTP headers (e.g., x-auth-request-roles)
Examples
Example 1: Admin-only component in navigation
Shows only if context is "navigation" AND user has "admin" role.Example 2: Multi-role component with path restriction
displayRules:
- allOf:
- contextName: toolbar
anyOf:
- role: admin
- role: editor
noneOf:
- path: "^/public/.*"
Example 3: Multiple rules for different contexts
displayRules:
# Show in desktop navigation for all users
- allOf:
- contextName: navigation
# Or show in mobile menu for authenticated users
- allOf:
- contextName: mobile-menu
anyOf:
- role: user
- role: admin
Example 4: Path-based conditional rendering
displayRules:
# Show settings only on settings pages
- allOf:
- contextName: sidebar
- path: "^/settings/.*"
Shows only when in "sidebar" context AND on a path starting with "/settings/".