Creates a shortcode block to test if a user is logged in or not and render content as desired.

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0


4.0.1 2018-12-11 02:26 UTC


Version License


  • SilverStripe CMS 4.2+


composer require fosforus/authblock-shortcode


In any shortcode-enabled editor field (HTMLEditor, et al.), place this shortcode around blocks of content you wish to "gate" based on the logged-in state of the user. E.g.: to show a specific block of content only to a user that is currently logged in:

[authblock auth="true"]Hello, member![/authblock]

To show content only to a logged-out (anonymous) user:

[authblock auth="false"]You may log in <a href="/Security/login">here</a>.[/authblock]

Note that due to shortcode nesting restrictions, you may not place shortcodes within the authblock. For more complex situations, consider creating custom template variables in your Controller(s).

You may also set a single permission to further qualify the authentication check, e.g.:

[authblock auth="true" perm="CMS_ACCESS"]Edit the site <a href="/admin/pages">here</a>.[/authblock]

In this case, if the user is not authenticated with the site or the user doesn't have access to any of the CMS (via CMS_ACCESS_* permissions), the block content will not show. Again, for more complex permission checks, extend your Controller(s).