Browser_mod.popup with a variable number of entities?

Hello, I’m building a generic browser_mod.popup for my dashboard where I want to have a variable number of entities displayed depending on the object that calls it.

For example, My current popup is configured to accomodate up to 6 entities but in this case I only use three of them. I used a dummy helper tag for the other three…

The code looks like this…

double_tap_action:
  action: fire-dom-event
  browser_mod:
    service: browser_mod.popup
    data:
      title: Device Control
      target:
        device_id: dd902a1fafdfbdb69d60722ba32aa964
      content:
        type: entities
        entities:
            - entity: '[[[ return variables.v_popup_entity1 ]]]'
            - entity: '[[[ return variables.v_popup_entity2 ]]]'
            - entity: '[[[ return variables.v_popup_entity3 ]]]'
            - entity: '[[[ return variables.v_popup_entity4 ]]]'
            - entity: '[[[ return variables.v_popup_entity5 ]]]'
            - entity: '[[[ return variables.v_popup_entity6 ]]]'

What I would like to do is make the entities array variable at run time so it only creates a popup with the exact number of entities that I need.

Any suggestions?