Skip to content

Table component - audio control option #1641

Done

Description

@SebastiendOrnano

What are you building with SQLPage ?

a table involving a playlist with audio control for each title

What is your problem ? A description of the problem, not the solution you are proposing.

it is not possible to introduce a audio tag in the table (or you have to unlock html_safe and it is not a good practice)

Describe the solution you'd like

add an option "audio" directly in the template "table"

Describe alternatives you've considered
I have developed a custom table.audio.handlebars which works by modifying :
{{~#if (array_contains_case_insensitive ../../markdown @key)~}} {{{markdown this}}} {{~else~}} {{~#if (array_contains_case_insensitive ../../icon @key)~}} {{~icon_img this~}} {{~else~}} {{this}} {{~/if~}} {{~/if~}}

by
{{~#if (array_contains_case_insensitive ../../audio @key)~}} {{#if this}} <audio controls preload="none"> <source src="{{this}}" type="audio/mpeg"> </audio> {{/if}} {{~else if (array_contains_case_insensitive ../../markdown @key)~}} {{{markdown this}}} {{~else if (array_contains_case_insensitive ../../icon @key)~}} {{~icon_img this~}} {{~else~}} {{this}} {{~/if~}}

and in my website
`
SELECT 'table_audio' AS component,
'Liste des poèmes' AS title,
'/z_advent/poems/poem_edit_4.sql?poem_id={id}' AS edit_url,
'/z_advent/poems/poem_delete_0.sql?poem_id={id}' AS delete_url,
'Titre' AS markdown,
'Audio' AS audio,
TRUE AS sort,
TRUE AS search;

SELECT
p.poem_id AS _sqlpage_id,
p.poem_id AS "N°",
'[' || p.poem_title || '](/z_advent/poems/poem_display_4.sql?poem_id=' || p.poem_id || ')' AS "Titre",
p.poem_author AS "Auteur",
p.poem_day AS "Jour",
p.poem_music AS "Audio"
FROM advent_poems AS p
ORDER BY p.poem_day;`

it works :

image

Additional context
Add any other context or screenshots about the feature request here.

Activity

  1. added
    enhancement
    on Nov 26, 2026
  2. lovasoa commented on Nov 27, 2026

    @lovasoa
    Collaborator

    I think audio in particular is too niche to be worth maintaining a new attribute in the table component. But I would love to allow writing custom html. And even better, it would be nice if across components, users could write custom html safely.

  3. SebastiendOrnano commented on Nov 27, 2026

    @SebastiendOrnano
    Author

    I understand your point of view ; a custom template is quiet easy to set up for those who are dealing with audio databases, so there is no emergency to introduce a new attribute.

  4. lovasoa commented on Nov 27, 2026

    @lovasoa
    Collaborator

    What I would love being able to do, is have something as clean as this in the sql.

    -- Proposed syntax
    SELECT 'table' AS component, TRUE AS sort, TRUE AS search;
    
    SELECT title AS "Poem",
           sqlpage.component('audio_player', json_object('src', audio_url)) AS "Listen"
    FROM poems;

    You would also write a small audio_player.handlebars file that would contain the html. And you could use it anywhere, including in other components.

    Internally, this requires us to be able to detect the provenance of attributes in components to escape them conditionally.

    I think it would unlock many new possibilities.

    @81reap, what do you think ?

  5. lovasoa commented on Nov 27, 2026

    @lovasoa
    Collaborator

    I opened an RFC in #1642

  6. lovasoa commented on Nov 27, 2026

    @lovasoa
    Collaborator

    What we can do in the short term is allow embeds like we do in the card component in the table component.

  7. lovasoa commented on Nov 27, 2026

    @lovasoa
    Collaborator

    In the next version of sqlpage you'll be able to do this:

    SELECT 'table' AS component, 'Audio' AS embed,
           TRUE AS sort, TRUE AS search;
    
    SELECT p.poem_title AS "Titre",
           p.poem_author AS "Auteur",
           CASE WHEN NULLIF(p.poem_music, '') IS NOT NULL
                THEN 'poem_audio.sql?poem_id=' || p.poem_id
           END AS "Audio"
    FROM advent_poems AS p
    ORDER BY p.poem_day;
    SELECT 'poem_audio' AS component, p.poem_music AS src
    FROM advent_poems AS p
    WHERE p.poem_id = CAST($poem_id AS INTEGER)
      AND NULLIF(p.poem_music, '') IS NOT NULL;
    <audio controls preload="none" src="{{src}}"></audio>

    Not as clean as sqlpage.component but I think we need some feedback before we implement that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions