somaromero / directus-extension-pdf-builder

A Directus flow operation to generate PDF documents with PDFMake.
MIT License
4 stars 0 forks source link

Question - How to use loop in template and display empty value with condition ? #5

Open bdloner opened 1 week ago

bdloner commented 1 week ago

For example I used for generate invoice in my order but I have many products and optional data send with null

For now, I show with only one product with array products[0].product_title I can't use products[i].product_title or use for loop

and null data It's display null or undefinded when my add_on.title but add_on is optional data I want to don't show when null data

how to make it

Thank you very much

somaromero commented 1 week ago

Thank you for your comment, @bdloner. I have a flow in Directus with its script node where you can see how we can render a set of data in a list. In a few moments, I will add it to the documentation of the wiki section so that you can review it. If there is any doubt, you can improve it so that it is as clear as possible. 📑

Wiki

bdloner commented 5 days ago
Screenshot 2567-11-12 at 01 25 36

Can I prevent data is null or undefined ?

For example

"text": "Adult: {{ read_order_detail.number_of_adult }} \n Child: {{ convert_and_reformat.number_of_child }}"

number_of_child it's optional value how to make "-" prevent display null or undefined in PDF ?

somaromero commented 3 days ago

Apologies for the delay. Currently, undefined variables are not supported directly. These can be handled using a Script node. However, I could add an option to allow setting a default value for variables that are undefined or null within the PDF generator node configuration. What do you think?