On Tuesday, September 15, 2020 at 5:44:56 AM UTC-7, Bob Jansen wrote:
>
> How can I check if a parameter passed to a macro is blank?
> I have tried
> \define purchased(name_id)
> <$list 
> filter="[tag[Artworks]!tag[Index]!<currentTiddler>search:name_id{[<<__name_id__>>]is[blank]then[XX]}sort[title]]}>&bull;
>  
> <$link to={{!!artwork_id}}><$view field="title"/> <$view 
> field="artwork_title"/></$link><br/></$list>
> \end
> but this does not work. If name_id is empty I want to search to look for 
> the string XX which I know doesn't exist.
>

First, as you may have realized, the above doesn't work because you can't 
"nest" filter syntax (i.e., you can't directly use a filter to describe 
another filter's operand value)

To accomplish your goal, first calculate the desired operand value and 
assign it to a variable.  Then reference the variable in the filter, like 
this:
\define purchased(name_id)
<$vars id={{{ [[$name_id$]!is[blank]else[XX]] }}}>
<$list filter=
"[tag[Artworks]!tag[Index]!match<currentTiddler>search:name_id<id>]">
   &bull; <$link to={{!!artwork_id}}><$view field="title"> <$view field=
"artwork_title"/></$link><br/>
<$list>
</$vars>
\end

Alternatively, since you know that searching for [XX] will result in no 
matching tiddlers, you could test for the blank value and just skip the 
$list entirely:
\define purchased(name_id)
<$list filter="[[$name_id$]!is[blank]]" variable="not_blank">
   <$list filter=
"[tag[Artworks]!tag[Index]!match<currentTiddler>search:name_id[$name_id$]]">
      &bull; <$link to={{!!artwork_id}}><$view field="title"> <$view field=
"artwork_title"/></$link><br/>
   <$list>
</$list>
\end
The outer filter is being used as a conditional ("if name_id is not blank") 
with the variable ("not_blank") used to avoid changing the value of 
<<currentTiddler>>.
Note: I like to use a variable name that summarizes the purpose of the 
filter, but you could use any variable name (e.g., "foo") since you really 
don't reference it anywhere.  

-e

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/ae75c768-803c-4bbb-9d71-20646a542e05o%40googlegroups.com.

Reply via email to