Template help, problem with multiple results

Hello,
hello,I have here a template with which I display the active media players.
if it is a single player who is active i have already gotten it solved but not with multiple results.

my problem is the following, if eg 3 players are active now I would like to have the title and the “entity_id.friendly_name” for each of them, the result should look like this

MediaPlayer1.friendlyname - Mediaplayer1.title
MediaPlayer2.friendlyname - Mediaplayer2.title
MediaPlayer3.friendlyname - Mediaplayer3.title

I think I have to create variables there? or what is the best way?

here is my code:

            {% set media_players = [
              states.media_player.plex_firetv_kueche,
              states.media_player.plex_shield,
              states.media_player.plex_firetv_schlafzimmer
            ] %}
            
            {% set media_players_playing = media_players | selectattr('state','eq','playing') | list %}
            {% set mediaplayers_name = media_players_playing | map(attribute='name') | join('\n') %}
            {% set mediaplayers_id = media_players_playing | map(attribute='entity_id') | join(', ') %}


            {% if (media_players_playing | length == 1) %}
              {{'\uD83D\uDCFA'}} {{ mediaplayers_name }}:
              {% if (state_attr(mediaplayers_id, 'media_content_type') == 'tvshow') %}
              {{ state_attr(mediaplayers_id, 'media_series_title') }}  
              {% elif (state_attr(mediaplayers_id, 'media_content_type') == 'movie') %}
              {{ state_attr(mediaplayers_id, 'media_title') }} 
              {% endif %}
              {% elif (media_players_playing | length > 1) %}
              {{'\uD83D\uDCFA'}} {{  media_players_playing | length }} sind an. 
              {% endif %}

actually he only counts and says “2 sind an” (2 are on)

thats works great, but one problem, he ignores the playing state, he shows me all players that are in “set media_players”.

i added this line

{% set media_players_playing = media_players | selectattr('state','eq','playing') | list %}

and changed this

{%- for player in expand(media_players_playing) -%}

that works great, is it possible to style the result? for example with fontsize? or ?

in a cutom-button-card, but i mean for example

{{'\uD83D\uDCFA'}} {{ player.name }}: <b> {{ title }} </b>

in this line only the {{ title }} with a tag, for a bigger font on the title?

its possible over a template sensor.

for example

- unique_id: sidebar
     state: template
     attributes:
        media_players: >
            {%- set media_players = [
              states.media_player.plex_firetv_kueche,
              states.media_player.plex_shield,
              states.media_player.plex_firetv_schlafzimmer
              
            ] | selectattr('state','eq','playing') | list -%}
            {%- for player in expand(media_players) -%}
            {%- set mct = state_attr(player.entity_id, 'media_content_type') -%}
            {%- set title = 'None' if mct not in ['tvshow', 'movie'] else state_attr(player.entity_id, 'media_series_title' if mct == 'tvshow' else 'media_title') -%}
            {{'\uD83D\uDCFA'}}<b>{{ player.name }}:</b><br>• {{ title }}<br>         

and the custom-button-card

- type: custom:button-card
            entity: sensor.template_sidebar
            template: sidebar

okay in your loop, is it possible to add a heading thats not visible when the loop is empty?
adding a heading is easy but he shows it still when the the loop is empty.
And i need the heading only one time, over the results from the loop.

for example:

MediaPlayer: (heading , only once, and only when the loop is not empty.)
Device1 – Title
Device2 – Title