How to refer to a given user?

Created on 27 June 2024, 5 days ago
Updated 1 July 2024, 1 day ago

Problem/Motivation

I am trying to do this (pseudo code coming up) -

{% If the user being viewed (NOT the current user) has role x %}
<div>field y</div>
{% endif %}

Bamboo Twig docs say, "if the current|given user has the requested role" but I can't see how to write the twig.

Please could you give a code example of how to refer to a given user in twig?

Steps to reproduce

I have a preprocess function which provides a $uid variable to my twig template for the user being viewed (NOT the current user) but I can't find a way to use that variable in the if condition.

I've tried loads things but most of the tips and snippets are for the current user.

Thank you

πŸ’¬ Support request
Status

Fixed

Version

6.0

Component

Documentation

Created by

πŸ‡¬πŸ‡§United Kingdom nigelwhite Marsden

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @nigelwhite
  • πŸ‡¬πŸ‡§United Kingdom nigelwhite Marsden
  • πŸ‡¨πŸ‡­Switzerland wengerk Lausanne

    Hello Nigelwhite,

    You can find the answer on the documentation > Usage > Security β†’

    The bamboo_has_role function returns a boolean if the current|given user has the requested role.

    • param1, role string.
    • param2, user int - User id instead of the current logged user.
    {% set user_id = 1 %}
    
    {# Does the given user have the given role ? #}
    {{ bamboo_has_role('authenticated', user_id) ? 'TRUE' : 'FALSE' }}
    
  • Status changed to Fixed 1 day ago
  • πŸ‡¨πŸ‡­Switzerland wengerk Lausanne

    Please re-open if you still have some questions about this security bamboo twig component.

  • πŸ‡¬πŸ‡§United Kingdom nigelwhite Marsden

    I understand it now and it works great.

    I've spent ages looking for a way so many thanks indeed.

Production build 0.69.0 2024