Closed andregoldstein closed 7 years ago
Hi. I don’t think Kirby is exposing $user
and $users
variables to templates. This is an example from the Kirby documentation:
<?php
$user = site()->user();
if($user->can('myplugin.permission', ['arg1', 'arg2'])) {
// user has permission
} else {
// user has no permission
}
Similarly, in Twig:
{% set user = site.user %}
{% if user.can('myplugin.permission', ['arg1', 'arg2']) %}
{# user has permission #}
{% else %}
{# user has no permission #}
{% endif %}
Note that if you want to write a lot of logic, you should probably do it in PHP in a controller, and only output your prepared data in the template. Twig is (in my opinion) simpler than PHP for outputting content, but it’s more limited and sometimes a bit verbose for logic and preparing content.
Brilliant, many thanks for pointing that out!
Hi there, is it possible to access other Kirby variables using Twig for example
$user
or$users
?Thanks