1

How can I display category name on template used in user->group.

{% for restaurant in craft.users.username(userId) %}
    {{ restaurant.name }}
    {{ restaurant.addressLine1 }} {{ restaurant.addressLine2 }}
    --
    // display the category name which has been added in restaurant->Group under Users
    --
{% endfor %}
  • Hi Mohit, would you mind following up on this question and letting us know if Brad's answer solved it or if you found your own way? You can add and accept your own answer here if you want! – Matt Stein May 9 '17 at 19:59
1

If I'm following you, you've got restaurants set up as user accounts in Craft and you've got a category field assigned to the Users field layout and you're trying to access those categories.

If so, it's as simple as it is in the docs: https://craftcms.com/docs/categories-fields#templating

{% set categories = restaurant.categoryFieldHandle %}

That will assign all of the categories to a variable named category. If you know there will only ever be one, then you can use:

{% set categories = restaurant.categoryFieldHandle.first() %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.