Memberz for Craft CMS

Twig reference

Everything is on craft.memberz, and everything is read-only. Nothing here writes, so a template cannot be talked into saving anything.

Forms

craft.memberz.form(handle, variables)Renders a form.
craft.memberz.getForm(handle)The Form model, for drawing your own.
craft.memberz.forms(type)All forms, optionally of one type.
craft.memberz.registerForm()The first registration form.
craft.memberz.registrationIsOpen()Whether Craft will accept a public registration.
craft.memberz.input(row, user)The front-end input for one row.
{% if craft.memberz.registrationIsOpen() %}
    {{ craft.memberz.form('register') }}
{% else %}
    <p>Registration is closed at the moment.</p>
{% endif %}

Directories

craft.memberz.directory(handle, params)Renders a directory. Reads the URL when params is omitted.
craft.memberz.getDirectory(handle)The Directory model.
craft.memberz.directories()All of them.
craft.memberz.members(handle, params)The UserQuery, or null if this visitor may not open it.

Profiles

craft.memberz.profile(user, form)Renders a member's profile.
craft.memberz.profileUrl(user)Their profile URL, or null if profile pages are off.
craft.memberz.accountUrl(tab)The account area, optionally a tab (profile or account).
craft.memberz.slug(user)Their profile slug, issuing one if they have none.
craft.memberz.fields(user, form)Only the rows this visitor may see.
craft.memberz.canSee(user, handle)Whether this visitor may see one field.
craft.memberz.canSeeProfile(user)Whether they may see the profile at all.
craft.memberz.value(user, handle)The value, or null if they may not see it.

The three that respect privacy

fields(), canSee() and value() apply the privacy rules. Craft's own accessors do not, because they know nothing about them:

{# Respects the member's settings. #}
{{ craft.memberz.value(member, 'jobTitle') }}

{# Publishes it regardless of who is looking. #}
{{ member.jobTitle }}

Photos

craft.memberz.avatar(user, size, attributes)A complete <img>, photo or fallback.
craft.memberz.avatarUrl(user, size)Just the URL.
craft.memberz.initials(user)Their initials.

Assets

craft.memberz.css()The shipped stylesheet, once per request. Templates place it for you.
craft.memberz.js()The optional runtime. Nothing includes this for you.
craft.memberz.settings()The plugin's settings.

A whole account page

{% requireLogin %}

<h1>Your account</h1>

<nav>
    <a href="{{ craft.memberz.accountUrl('profile') }}">Profile</a>
    <a href="{{ craft.memberz.accountUrl('account') }}">Account settings</a>
    <a href="{{ craft.memberz.profileUrl(currentUser) }}">View your public profile</a>
</nav>

{{ craft.memberz.form('profile') }}
{{ craft.memberz.js() }}

Handling a submission

Forms post to memberz/account/register or memberz/account/save. On failure the account model comes back on the route under both user and the form's own handle, so a page with two Memberz forms on it can redraw the one that failed without the other picking up its errors:

{% set failed = register ?? null %}
{% if failed and failed.getErrors() %}
    <ul>
        {% for messages in failed.getErrors() %}
            {% for message in messages %}<li>{{ message }}</li>{% endfor %}
        {% endfor %}
    </ul>
{% endif %}

For an Ajax submission, send Accept: application/json. Success answers with a message and the account's id — never the account itself, because that payload would publish every field on it, including the ones the form deliberately does not show.