{cannot}
Renders its content when the user may not do something a gate decides - can turned round.
Syntax
{cannot 'ability', $value} ... {/cannot}
{cannot 'ability', $value} ... {else} ... {/cannot}
Parameters
-
ability -
The name of a gate defined with
padGate. -
values -
Optional, any number: what the gate is given after the user, as for
{can}.
Description
{cannot} is {can} turned round: the content renders when the gate answers no, and the part after its own {else} - or the @else@ half - when it answers yes. Everything else is the same: the first item is the ability, the others what the gate is given, an enclosing loop's name its current row.
A guest is refused by every gate that does not take NULL for its user, so for a guest {cannot} renders its content for those. An ability nobody defined counts as no - and is an error under the strict check, as with {can}.
Examples
The opposite of can
The content renders when the gate says no - here for the post a guest may not read.
<ul>
{posts}
<li>{$title}{cannot 'read-post', $posts} <span class="badge">locked</span>{/cannot}</li>
{/posts}
</ul>
<?php
$posts = [
[ 'title' => 'Release notes', 'published' => TRUE, 'author' => 1 ],
[ 'title' => 'Draft: roadmap', 'published' => FALSE, 'author' => 1 ] ];
?>
- Release notes
- Draft: roadmap locked
With an else
{cannot} owns its {else} too: the part after it renders when the gate says yes.
{set $note = [ 'title' => 'Minutes', 'published' => TRUE, 'author' => 7 ]}
{cannot 'edit-post', $note}
<p>You cannot change these minutes.</p>
{else}
<p><a href="#edit">Change the minutes</a></p>
{/cannot}
You cannot change these minutes.
See also
- {can} Renders its content when the user may do something a gate decides, and its else half when not.
- {auth} Renders its content when a user is logged in, with the user's row as its data, and its else half for a guest.
- {guest} Renders its content when nobody is logged in, and its else half for a user.