I gotcha buddy. This was a great question and I thought it would be educational for me to find out too. I had to examine Grav docs, Twig docs, Grav community, Stack Overflow and data dumps of running Grav instances but got there in the end!:
{% for group in grav.user.groups %}
{% if group == "aaa" %}
<p>AAA only</p>
{% endif %}
{% if group == "bbb" %}
<p>BBB only</p>
{% endif %}
{% endfor %}
Since we are using dynamic Twig variables we don’t want the processed Twig to be cached (otherwise a BBB user could see cached AAA content). So in the frontmatter of the page with your content, add:
never_cache_twig: true
Thank you @onemhz for helping me help you help me by helping you!
Note that if the user is in both groups, the above code will show content for both. BBB content could actually appear before AAA content if the group was created first. The order follows /user/config/groups.yaml or whatever array manipulation you do.
never_cache_twig: true is also “not compatible with twig_first: true currently because all processing is happening in the one Twig call.”