{#
SAM Entity Tag Component - Tag/link to an entity (course, cohort, user)
Parameters:
- text: string (required) - Tag text
- type: string - Entity type: 'course', 'cohort', 'user'
- url: string - Optional link URL
- truncate: number - Max characters before truncation (default: 30)
- icon: bool - Show entity icon (default: false)
- size: string - Size: 'sm', 'md' - default: md
Usage:
{% include 'sam/_components/entity_tag.html.twig' with {text: 'Formation PHP', type: 'course', url: courseUrl} %}
{% include 'sam/_components/entity_tag.html.twig' with {text: 'Cohorte 2024', type: 'cohort', truncate: 20} %}
#}
{% set entityType = type|default('course') %}
{% set maxLength = truncate|default(30) %}
{% set tagSize = size|default('md') %}
{% set displayText = text|length > maxLength ? text|slice(0, maxLength) ~ '...' : text %}
{% set entityIcon = {
'course': 'book',
'cohort': 'layers',
'user': 'user'
} %}
{% set tagClasses = ['sam-entity-tag', 'sam-entity-tag--' ~ entityType, 'sam-entity-tag--' ~ tagSize] %}
{% set tag = url is defined and url ? 'a' : 'span' %}
<{{ tag }}{% if url is defined and url %} href="{{ url }}"{% endif %} class="{{ tagClasses|join(' ') }}" data-tooltip="{{ text }}">
{% if icon|default(false) %}
{% include 'sam/_components/icon.html.twig' with {name: entityIcon[entityType]|default('file'), size: tagSize == 'sm' ? 10 : 12} %}
{% endif %}
{{ displayText }}
{{ tag }}>