I just discovered the HTML > PDF generation option in Fibery, which looks really useful. I added a button to one of my databases that uses the Attach PDF action to generate the PDF into a Files field, and I have “Treat Template as HTML page” checked. Most of this is working great, but I’m running into trouble when trying to include a list of entities in my template.
I have a database called “Meals” and a database called “Dishes”. Meals have a one-to-many relationship with Dishes. I want to display the name of the Meal at the top of the PDF (simple enough) and then below that have a bulleted list with the names of each Dish connected to that Meal. The button that calls the PDF generation is on Meals.
If I use Markdown {- Dishes:Name -}, the PDF generates successfully, but the names of the Dishes are all listed in one long line, rather than a styled vertical bulleted list:
If I use HTML and JavaScript as shown here:
<table>
<% for(let item of Entity.Dishes) {%>
<tr>
<td><%= item.Name %></td>
</tr>
<%}%>
</table>
…then the PDF fails to generate and I get a popup error that says “Failed to execute Action “Attach PDF To Printable PDF Using Template”: Entity.Dishes is not iterable.” (“Printable PDF” is the name of my Files field.)
I tried this as an unordered list, too (I’d actually prefer to use that than a table in this case), but got the same error.
<ul>
<% for(let item of Entity.Ingredients) %>
<li> <%= item.Name %> </li>
<% %>
</ul>
I also tried it using the formatting used in this documentation, but again, same error.
<% for (const item of Entity["Dishes"]) {%>
- <%= item.Name %>
<% } %>
Any idea what I’m doing wrong here? (Or alternatively, is there a way to style the markup version and I can bypass using JS altogether?)
My full template code:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
font-family:Trebuchet MS,Sans-Serif;
}
</style>
</head>
<body>
<h1>{{Name}}</h1>
<ul>
<% for(let item of Entity.Ingredients) %>
<li> <%= item.Name %> </li>
<% %>
</ul>
</body>
</html>
