helloflask / bootstrap-flask

Bootstrap 4 & 5 helper for your Flask projects.
https://bootstrap-flask.readthedocs.io
Other
1.1k stars 189 forks source link

render_table and multiline #212

Closed serensoner closed 1 year ago

serensoner commented 2 years ago

hey there, i'm using render table with a field that sometimes has multilines (separated by \n, or possibly <br />. is there a way to show this as multilines using render_table? i tried render_table(...)|safe and render_table(data, ..)|safe but neither worked. any ideas?

PanderMusubi commented 2 years ago

I'm looking for something similar but to add e.g. <a href="https://blahblah.blah/?q=CELL%20CONTENT">CELL CONTENT</a> in a cell the would normally show CELL CONTENT. Would it fix our cases and other cases if we could pass a list of tuples with columns names and a macro to be called for each cell in that column for a table?

An example would be:

render_table(...., macros=[('Category', 'my_macro')])

with implementation (in pseudo code)

if title[1] in macros:
#    <td>{{ macros[title[1]](row[title[0]]) }}</td>
# which results in
    <td>{{ my_macro(row[title[0]]) }}</td>
else:
    <td>{{ row[title[0]] }}</td>
PanderMusubi commented 2 years ago

@serensnoer, for you what would be using self() instead of my_macro().

PanderMusubi commented 2 years ago

@serensoner see https://github.com/greyli/bootstrap-flask/pull/204 which offers safe for specific columns.

greyli commented 1 year ago

Implemented in #204.