Try this instead of the foreach
line: (untested)
{html, lists:map(fun(X) -> {Id, Fname, Lname} = X, io_lib:format("ID: ~p ", [Lname]) end, Data)}.
That is, instead of printing using io:format
, return the data in a {html, Iodata}
tuple, as in the first <erl>
block.