ngs-doo / TemplaterExamples

Creating reports in .NET and Java
https://templater.info
The Unlicense
48 stars 27 forks source link

Problem with removing empty tables #14

Closed edobosz closed 4 years ago

edobosz commented 4 years ago

daily_data_example.txt

Hello, I want the table to be deleted from document when there is no data inside. Normally, when there are no records, Templater generates table with header only. I want Templater to remove header also, I was trying to achieve this in a few ways. In user manual I found section "Removing a table". I putted collapse and hide metadata into header like it's described in user manual, but it gave no result. Then, I was trying to implement method similar to CollapseNonEmpty in wordtables example. After many tries I'm getting a lot of weird results. I don't exactly understand how Templater process data and what is current "context" when it's processing. I don't want to write all my observations and conjectures, but I've putted many breakpoints and spent many hours to understand Templater logic, but unfortunately I can't figure it enough modify this to my purposes.

I attach template and example data (in JSON for clearness) to show data structure.

Please, could you provide me solution or help to make solution for this problem? I don't have any other ideas. For now Templater is still almost like black box for me and I need help from creators. Thanks a lot. daily_demo.docx

zapov commented 4 years ago

Hi,

I suppose the example is somewhat misleading as it only works in some narrow cases. What works in all cases is when you use a property from the collection, not just the baseline property. Eg if you are on .NET you can access .Count from the leg list and it will behave as expected even with this nesting, while using something like [[aircraft.leg]:hide] will only work when there is no nesting.

daily_demo_count.docx daily_data_example.txt

ps. I also put an empty item in your JSON as it was missing

Hope that clarifies things.

edobosz commented 4 years ago

Hi, I'm sorry, I didn't point what collection I mean exactly. I mean crew collection inside leg. I want to remove crew table when there is no records.

I'm trying to use your aprroach in crew table, but I'm getting error 'Tag [[aircraft.leg.crew.Count]:hide] has been resized more than 8 times. This probably indicates a configuration error in the template.' I'm putting [[aircraft.leg.crew.Count]:hide] in header cell.

Do you have any ideas where this error come from?

zapov commented 4 years ago

Usually that message is the result of bad template setup. It's hard to say whats going on without you providing template and data.

The one you provided work fine when I fix the JSON path in document.

daily_data_example.txt daily_demo_count.docx

zapov commented 4 years ago

I will assume this work as expected now. If the issue is something else, please provide more info