#[SOLVED] Read table data from toml file

7 messages · Page 1 of 1 (latest)

half iron
#

Hello, I want to read table data to display upcoming events from a toml file. Here is what I got:

My TOML-File looks something like this:

[[event]]
date = 2024-03-02
name = "Nice event"
comment = "Please show up"
#let events = toml("events.toml").event

#table(
  columns: 3,
  table.header(
    [Date],
    [Event],
    [Comment],
  ),
  for event in events {
    table.cell(termin.date.display())
    table.cell(termin.name)
    table.cell(termin.comment)
  }
)

This works with the exception that all three fields are displayed in the first table cell. Not in their respective table cells. How do I fix this?

remote jewel
#

Right now, you are joining all three table cells together into one content block.

#

table expects a variadic amount of content as its children, so you should ideally map your toml data to a one dimensional array and spread it in the table

#

?r

#let toml-content = "
[[event]]
date = 2024-03-02
name = \"Nice event\"
comment = \"Please show up\"

[[event]]
date = 2024-03-03
name = \"Nice event\"
comment = \"Please show up\"
"

#let events = toml.decode(toml-content).event
#let events-arr = events.map(e => (
  e.date.display(), e.name, e.comment
))

#table(
  columns: 3,
  table.header(
    [Date],
    [Event],
    [Comment],
  ),
  ..events-arr.flatten()
)
remote jewel
#

kinda like this (there might be a nicer way)

half iron
#

This solves it. Thank you very much!