The add property

Under some situations, one card needs to collect data from other cards: the content of this card should actually be the collection of other cards' content.

The add property, available from any cards, accepts queries to attach/embed other pages' data to it.

For example, one all projects card needs data from other cards of type = project.

In traditional CMS, the template can query the database itself and retrieve those projects before fetching anything. But in static-oriented sites, templates are static and don't do much: they just expose placeholders to be filled. For this reason, the logic is a bit different, and templates need to receive all data they need without further efforts.

Thus, in our example, add would allow Troglio to attach those projects data into the all projects card, and just copy the relevant cards' data into a property named data (see below).

The add property accepts the same queries as in mongoDB. So, here is an example of adding all pages of type projects to a page:

add = {"type": "projects"}

+++

Body of page is here...

IMPORTANT: note that anything coming after add = is actual JSON, meaning it needs keys in double-quotes and values separated by a colon :. However, as this is TOML, one can get the same output using:

[ add ]
type = projects

 +++

Body of page is here...

We prefer the first JSON form because we can easily copy-paste some mongoDB queries as-is and they should work out of the box :)

This is the most complicated concept of Troglio and if you understood it: everything else is a piece of cake :)

Like exposed above, the add property only holds the query. The result of this query will be available in the data property of the said card. So, to close our example, developers should see resulting data like this:

"data" : [
   {...},
   {...},
   {...},
   {...},
]

where each {...} represents one card of type = project. Makes sense ?!