I would guess you're using phplib templates?
Parse the embedded template and append to it.
$t -> set_file(array(
"rows" => "detail.ihtml",
"body" => "body.ihtml"
));
while ($db->next_record()) {
$t -> set_var($db->Record);
$t -> parse("Detail", "rows", TRUE);
}
// Parse the body which contains a {Detail} and print
$t -> pparse("output", "body");