Any element on a portal page can be shown or hidden at render time using one of two attributes. In the builder both are configured from the Visibility modal, opened with the eye button on the component toolbar (the handle that also offers move, clone and delete). You can also add the attributes by hand in the HTML editor. Conditional display runs after merge tags are substituted, so conditions can reference live record values.
Select any component on the canvas and click the eye icon in its toolbar. The icon changes to a crossed eye when the component already has a rule. The modal has four parts:
| Part | What it does |
|---|---|
| Show this component | The preset: Always, Only to logged in users, Only to guests, Never. Stored as component-visibility. |
| Hide when this JavaScript rule is true | A JavaScript expression, stored as hide-if. The component is removed when it returns exactly true. |
| Merge variables | Click to insert. Global variables ({{recordId}}, {{sessionKey}}, {{contactUser.Id}}, {{contactUser.FirstName}}, {{contactUser.LastName}}, {{contactUser.Email}}, {{contactUser.Phone}}, {{contactUser.AccountId}}, {{contactUser.Account.Name}}, {{page.Title__c}}, {{portal.Name}}) and every accessible field of the selected test object as {{record.Field}}. |
| Test the rule | Pick an object (default Contact) and a record, choose whether to evaluate as a logged in user, then click Run test. |
Apply writes the attributes to the component; Always and an empty rule remove them so the html stays clean. The previous Hide If and Visibility traits in the properties panel have been replaced by this modal. Existing attributes are kept and show up in the modal unchanged.
Run test merges the rule on the server against the selected record (record.* and {{recordId}}), using the portal's emulated contact for contactUser.* or, when no emulated contact is set and the record is a Contact, the selected record itself. The merged expression is then evaluated in the browser with the same code the runtime uses, and the modal reports:
The tester is only available to internal users in the builder (Apex PortalSchemaService actions searchRecords and mergeExpression, both rejecting guest sessions and running with sharing). Nothing is saved until you click Apply.
Show or hide based on login state. Values:
| Value | Behaviour |
|---|---|
show (default) |
Always shown |
show-when-logged-in |
Removed unless the user is logged in |
show-when-guest |
Removed when the user is logged in |
hide |
Always removed |
Examples:
<div component-visibility="show-when-logged-in">Members only content</div>
<a component-visibility="show-when-guest" href="@login">Log in</a>
component-visibility is evaluated first and overrides hide-if.
Remove an element when a JavaScript expression evaluates to boolean true. The attribute value is a JavaScript condition. Because it runs after merge, substituted values are already in place:
<div hide-if="'{{record.Status__c}}' !== 'Active'">Active badge</div>
<div hide-if="{{record.Cases.length}} === 0">You have no open cases</div>
The element is removed only when the expression returns exactly true. If the expression returns a non boolean, the element is kept and a warning is logged.
At render, the runtime parses the page HTML, finds every element with a hide-if or component-visibility attribute, evaluates the rule, and removes elements that should not show before inserting the HTML into the page. The x3b-custom-body class and the page body classes are preserved.
hide-if expressions and any page level JavaScript are executed without a sandbox, by design, because templates are authored in the trusted builder. Do not accept hide-if expressions or page HTML from untrusted sources. Keep page authoring restricted to trusted builder users.
Conditional display pairs naturally with repeatable lists. For example, hide an empty state when a list has records, and hide the list when it is empty:
{{! filter: Status = 'Open'}}
<div hide-if="{{record.Cases.length}} === 0">
{{#record.Cases}}<p>{{Subject}}</p>{{/record.Cases}}
</div>
<div hide-if="{{record.Cases.length}} > 0">You have no open cases.</div>