Lesson notes
How it works
How Memberstack hides an element when a custom field is blank
Every member has custom fields, like a name, a company or a bio. You create them in the dashboard and members fill them in through Memberstack forms. MemberScript #10 uses those values to decide whether an element stays on the page.
When the page loads, the script reads the logged-in member's data that Memberstack keeps in the browser. It then finds every element with the ms-code-customfield attribute and looks up the field named in that attribute. If the field is empty or missing, the script removes the element from the page. If the field has a value, the element stays.
You can flip the logic by putting ! in front of the field ID, for example ms-code-customfield="!name". Now the element is removed when the field is filled in. That is handy for a "Finish your profile" prompt that should disappear once the member has done it.
Set it up in Webflow
The script needs no edits. All the setup is one attribute per element.
- In the dashboard, go to Members and click the Custom Fields button in the top right. Create the field if it doesn't exist yet.
- Click the pencil icon next to the field to see its ID. The attribute must use this ID, not the label.
- Paste MemberScript #10 into your page's body code (or site-wide if you use it on many pages).
- Select the element you want to control and add the attribute
ms-code-customfieldwith the field ID as the value, for examplems-code-customfield="name". - Publish, log in as a test member, then clear and fill the field with a profile form (
data-ms-form="profile"with an input likedata-ms-member="name") and refresh each time.
Use it for display, not for protection
Custom fields live on the member and can be changed from the browser. Memberstack's docs are clear that you should never gate content with custom fields or member JSON, because a member could work around it. Use this script to tidy up what a member sees, like hiding an empty "Website" link or a profile badge. To lock content, use plans and gated content.