How do you include the first child note from a list?

For the life of me I cannot figure out how to do a fairly simple task. I have a homepage that I want to show the content of the latest note from a list. I’ve tried many different iterations of include, value, collect and I cannot seem to get it. The content never appears. I’ll do something like:

^include(collect(children(/Recipes Raw), $Text).first)^

I think in general I’m having a hard time figuring out code that manipulates lists of notes. I understand collect, but I’m looking for the code that operates on notes rather than attributes of notes.

@mwra This is actually my first pass at the Tinderbox Cookbook that we discussed in the previous meetup. I’ve attached it to this post. Please let me know if you have any ideas about structure. (the images will be missing since I have not included them). Specifically, in this file, I was hoping to have the first note from Recipes Raw included in index (next to the navigation list).

TBX Cookbook.tbx (151.5 KB)

There are a few ways to do this.

  1. The simplest is to use the designator child, which is the eldest or first child of the container.

  2. If you need the nth child, you can say child[n].

  3. If you have a list of paths, you can get the first member of the list as $MyList.first.

  4. The first(which,n) operator returns a list of the first n items in the designated container.

Looking at your proposal,

^include(collect(children(/Recipes Raw), $Text).first)^

We begin with collecting the texts of all the children of Recipes Raw: collect(children(/Recipes Raw), $Text). Then we keep only the first text, and assume that’s the name of the note we want. This is probably not what you wanted to do; perhaps you meant to build a list of $Path rather than Text.

What I’d do is this:

  1. Set up your include: ^include($MyString) , where you enter the path of the note you want to include in $MyString. I think that will work, but you might need ^include(^value($MyString)).

  2. When that’s working, figure out an action that computes the path you want, and stores it in $MyString. For example, $MyString=$Path(child(/Recipes Raw))

  3. Perform that action in the export template, or in a rule.

2 Likes

Ah! I forgot about using $Path… that makes way more sense.

2 Likes