Using Access Groups for Conditional Visibility
Here's what we're thinking...
Last updated
Was this helpful?
Here's what we're thinking...
Last updated
Was this helpful?
At this point our discussions are focusing on two key use cases for Access Groups;
Conditional visibility of elements
Routing
Currently, you can check for access-group inclusion by checking the array, e.g.;
This technique can be used with custom code to hide, show, create, or remove elements.
Let's suppose you have several elements that you only want to appear when the user is in an access group named
pro
, and you want those elements deleted from the DOM otherwise.
Setup;
Create a global class, we'll call it access-group-pro
for simplicity.
Assign it to all elements that you want to appear only for your pro
access group members.
Set the style to display: none, so that it is initially hidden, until access group can be determined.
SECURITY: if you are working with any form of sensitive data, this is not a means to secure that data. Even removing the element will not prevent prying eyes from finding it if they simply disable javascript and examine your page source.
We're looking at adding conditional visibility support to SA5's Data-Binding lib. Currently our thinking is this;
Add two new attributes;
wfu-bind-show
will display an element, only if its data-bound value is truthy
wfu-bind-hide
will hide an element if its data-bound value is truthy
Add a new internal binding resolver piece to the architecture which is source-aware. Regarding the User Object, it will resolve the access_groups
array into a bindable boolean value.
This would support attribute constructions like;
wfu-bind-hide
= $user.access_groups.basic
With this you can make elements conditionally visible on the basis of a single access group.
The reason for both a show and a hide variant is that it allows easily for a default state.
Later, deprecate [wfu-show-logged-in]
with an SA5 Data-Binding approach, e.g.
wfu-bind-show
= $user.logged_in
Use cases;
On entry into any page, e.g. /my-page
redirect the user based on their presence / absence from an access group.
Modify URLs and button links depending on a user's presence / absence from an access group.
This feature would probably benefit from some concept of zoning as a part of the routing architecture, so that you can broadly group pages and elements into an access zone. This would work in conjunction with Webflow's current access-group gating.
For this type of operation, are quite useful since they can be applied on top of other class arrangements. Alternatively, simply wrap your elements in a DIV and assign your pro-users
class.