I’ve created callouts for tabletop RPG data that I pull in with meta-bind-embed.
The Vehicle Infobox note contains Setting Info:
Code for the “Variants Include” table:
> ```dataview
> TABLE WITHOUT ID ModelsInclude AS "Variants Include"
> FROM "Mechanics"
> WHERE (file.name = this.file.name)
> ```
The Vehicle Stats Infobox not contains Vehicle Stats:
Code for the “Armament” and “Attachments” tables:
> ```dataview
> TABLE WITHOUT ID Weapons AS "Armament"
> FROM "Mechanics"
> WHERE (file.name = this.file.name)
> ```
> ```dataview
> TABLE WITHOUT ID Attachments AS "Attachments"
> FROM "Mechanics"
> WHERE (file.name = this.file.name)
> ```
The main note is called A-A4B Speeder Truck. Here is a snippet of the relevant properties as well as the subsequent meta-bind-embed calls that pull the infoboxes into the page, followed by the article text:
What I’m trying to do
I only want dataview tables (such as Variants Include, Armament, and Attachments) to appear if they contain a value. If there is no value, I want to hide the table entirely, like this for Vehicle Stats Infobox:
Things I have tried
I understand that dataviewjs is the way to do this, but my coding knowledge is woefully inadequate. I referred to Hide empty dataview queries but so far have been unable to repurpose the code. (I’m using the “Armament” table as a guinea pig - if I can get it to work there, I assume I can apply the same principle everywhere.)
Here’s the updated dataviewjs Armament table code in Vehicle Stats Infobox below. It replaces the original dataview Armament table code (seen above):
> ```dataviewjs
> // place your query here
> const query = `TABLE WITHOUT ID Weapons AS "Armament"
> FROM "Mechanics"
> WHERE (file.name = this.file.name)`
>
> // executing the dataview query and return results
> let DQL = await dv.tryQuery(query);
>
> // render the table only if any value
> if (DQL.values.length > 0){
> dv.table(DQL.headers, DQL.values)
> }
> ```
When rendering Vehicle Stats Infobox in Reading mode, a note with no properties whatsoever, the table is correctly absent - yet when I add the Weapons property with a dummy entry, the table never appears.
However, when rendering the A-A4B Speeder Truck note in Reading mode, the table header is always present, even when the Weapons property is empty. Adding a dummy entry correctly updates the table:
I’m not entirely sure where to go from here. I tried returning DQL.values.length to troubleshoot but got no results, no matter what I tried. I fear my dataviewjs/JavaScript knowledge is too basic. Any ideas?