I have a collection of Notes, each with a date ($ MyDate). I would like to export only one Unique date for all the notes that have the same date.
I think I need to compare the $MyDate of the PreviousSibling to the current note and only export the value of $MyDate if they are not the same. Is this the correct logic ? I do not know how to do this in TB.
Are there any videos that could help me understand this better, or if the problem requires a loop, understand the programming logic /syntax better?
In my main file, the notes are collected by an agent, but I assume the same theory applies.
I’ll upload my edited version for you file at the end of the post. But the main assumptions are as follow…
We will use a container or agent for export. In either case:
$Sort set for ‘MyDate’, reverse order
$SortAlso set for ‘Name’
So, all children/aliases sort in reverse ($MyDate) date order—i.e. most recent first—and in A–Z order within groups of notes with the same MyDate.
We need two new templates:
t_date-page. This is the ‘wrapper’ template used by the agent or container to generate the list. It transcludes each child using template…
t_date-item. Checks if current note is first sibling or has a different $MyDate to its previous sibling. If so, the formatted $MyDate is listed before the note’s data ($Name, etc.)
The code in the latter template looks like this (ignore the forum’s code-colouring which is getting confused here):
Note that sibling order is intrinsic so as long as the parent container/agent is sorted correct see above), the code works fine with original notes or aliases in an agent.
Also note that when using == or != with Date type data, the time portion of the Date/time data is ignored. To illustrate this I changed the time of day, but not the day in several notes (‘Bobcat’, ‘Lynx’). This is why the outline sort order may differ slightly from that expected. To sort ($Sort) only on day and not date-time of $MyDate you would need to store the date-time in another attribute, but re-setting the time portion of each to the same time.
I’ve added an agent to the TBX so you can see the same template working in either a container or an agent listing that container’s contents.
Not at all - I think that’s a lovely idea. I’m sure there’s more that can be pulled out of the scenario. I really just tested the ‘am I like my sibling?’ aspect and that it works for either a container or an agent.