Tinderbox Forum

Filter children by prototype in HTML template

I have a Note that contains children (cities) and grandchildren (notable locations). In the root note, I’m exporting out a page that will show all locations regardless of hierarchy, categorized by type. For the life of me, I cannot figure out how to filter descendents by prototype. I was expecting to do something like:

^descendants({template here}, $Prototype==“pCity”)^

Below is the basic HTML template I’m using. Any ideas?

<!DOCTYPE html>
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!--   ** Standard Tinderbox Template [section page] **  -->

	^children(/Templates/City/Location Item)^
	^children(/Templates/City/Location Item)^

There are lots of ways to do this! Much depends on what else you want to do; I’m going to suggest one way to do this, but there are others.

  1. Make an agent that collects all the cities.
  2. The agent’s export template builds a list of its children.
  3. Your page template now does ^include(CityAgent) to list the cities.
  4. Now, make an agent that collects all the notable locations.
  5. Again, this agent’s export template builds a list of its children. You might reuse the template from the CityAgent.
  6. Your page template now does ^include(LocationAgent) to list the locations.

Another approach: add conditional logic to the export templates for cities and for locations, so they export nothing if the note is the wrong kind of note, and tailors the export as you prefer.

^if($Prototype=="pCity") <li>  <em> $Name </em> </li> ^endif
^if($Prototype=="pLocation") <li>  $Name </li> ^endif

Another approach would be to inherit the appropriate template from the prototype. So, cities get the CityTemplate

<li>  <em> $Name </em> </li> 

and locations get the LocationTemplate. That’s the most idiomatic approach, but you may already be using it to tailor the export of the city and location pages.

1 Like

@eastgate Perfect! I went with solution #2 for now. On a related note, I have a simple blog that I’ve been building. I would like to use agents as a way to create lists of articles, but I found when I did so, the HTML export duplicated files (files in their original locations, then files in the agent as well). What’s the best way to have a bunch of agents that can be used as aggregators of links in exported HTML, but they don’t duplicate the files and instead reference the source files original location?

Set the agent’s $HTMLExportChildren to false to avoid exporting the agent’s children.

I tried that, but then the agent content wasn’t appearing in my other HTML templates. But I’m guessing I did something wrong. I’ll try again and come back if I get stuck. Thanks!