Returning tiddlers which contain items from the current tiddler's list field

I am working on some tools to help me with meal planning and I’m running into a couple issues. So far, I have created a template for a weekly meal plan, and a recipe list that can be filtered and has a macro to add new recipes. My ultimate goal is to be able to list recipes with similar ingredients to the meals already added on my meal planning template.

I wrote a macro to add ingredients to recipes:

\define addIngredient()
<$action-listops $field="ingredients" $subfilter={{!!new_ingredient}} />
\end

<$edit-text tiddler=<<currentTiddler>> field="new_ingredient" tag="input" default=""/>

<$button actions=<<addIngredient>>> Add Ingredient </$button>

The first issue is that I’m having trouble figuring out how to automatically add the double brackets around ingredients with spaces.

The second issue is figuring out how to list all of the other recipes that have any of the ingredients that are in a tiddler’s ingredients list.

Any help that you can provide is greatly appreciated!

The first issue is that I’m having trouble figuring out how to automatically add the double brackets around ingredients with spaces.

The value of the $subfilter parameter should be using filter syntax. Instead of writing:

$subfilter={{!!new_ingredient}}

you should be writing:

$subfilter="[{!!new_ingredient}]"

i.e., a filter expression that contains a single item… the input text stored in the “new ingredient” field.

The second issue is figuring out how to list all of the other recipes that have any of the ingredients that are in a tiddler’s ingredients list.

You can use the contains filter operator to search the ingredients list in other tiddlers:

<$list filter="[all[tiddlers]contains:ingredients{!!new_ingredient}] -[<currentTiddler>]">
   <$link/><br>
</$list>

enjoy,
-e

1 Like

Thank you, that helps a lot!

The new subfilter worked perfectly.

That worked great for a field with just one ingredient, but I’m trying to use this with the ingredients field, which would be a list of several items. So, for example - if I had a recipe for tacos with beef, taco shells, and lettuce as the ingredients, I would want the list to show all recipes that have beef, taco shells, or lettuce in their ingredients field. Do you know whether it’s possible to do an iterative search like that? I tried the search operator, but I haven’t had any luck with it yet.

TiddlyBob, when a tiddler or field contains a list of titles, you make use of the listops filters and widgets. This ensures the titles are handled correctly, then using enlist or list operator’s to extract a list of titles from such fields. You can also reorder title in such fields with the list-links-draggable Macro.

Regards
Tony

1 Like

That makes sense - thank you! I will read up some more on the listops widget.

1 Like

Give this a try:

Other recipes containing any of: ''<$text text={{{ [enlist{!!ingredients}join[, ]] }}}/>''
<blockquote>
<$list filter={{!!ingredients}} variable="ingredient">
   <$list filter="[all[tiddlers]contains:ingredients<ingredient>] -[<currentTiddler>]">
      <$link/> contains ''<$text text=<<ingredient>>/>''<br>
   </$list>
</$list>
</blockquote>
3 Likes

Brilliant! That did the trick. Thanks so much!

Regards,
Bobby