Need "get $note$, and if no $note$ content, get tiddler title"

Hi everyone

After the recent update to my Subsume plugin, I got a hankerin’ for more.

All I need to make it work is a way to check to see if a macro parameter has text, and use it as the summary of the details element; if the parameter is empty, then it should use the tiddler title as the summary.

Below is what I have so far:

\define viewme(note:"" tid:"")<details><summary>$note$&nbsp;&nbsp;<$button class="tc-btn-invisible"><$action-sendmessage $message="tm-edit-tiddler" $param="$tid$" />&nbsp;^^{{$:/core/images/edit-button}}^^&nbsp;</$button></summary><span class="indent1"><$transclude tiddler="$tid$" mode="block"/></span></details>

$tid$ is the tiddler transcluded in the details element, and $note$ is the text that gets displayed to the details summary. <<viewme note:"foo" tid:"bar">> results in the equivalent of this:

<details><summary>foo [button to edit bar]</summary>

{{bar}}

</details>

But I can see cases in which I would like to write <<viewme note:"" tid:"bar">> and have the output be

<details><summary>bar [button to edit bar]</summary>

{{bar}}

</details>

So is there a way to have it grab $note$ if there is something there, but if not, grab $tid$ instead?

Not the full meal deal, but I think you need a piece like in:

\define viewme(note:"")
<$text text={{{ [[$note$]is[blank]then[note is blank]else[$note$]] }}}/>
\end

<<viewme>>

Try this:

\define viewme(note,tid)
<$let note={{{ [<__note__>!match[]else<__tid__>] }}}>
<details>
   <summary>
      <<note>>
      <$button class="tc-btn-invisible" message="tm-edit-tiddler" param=<<__tid__>>>
         ^^{{$:/core/images/edit-button}}^^
      </$button>
   </summary>
   <span class="indent1"><$transclude tiddler=<<__tid__>> mode="block"/></span>
</details>
\end

Notes:

  • For readability, I reformatted your macro definition to use multiple lines.
  • Use <<__param__>> (“parameter-as-variable”) instead of $param$ just in case a parameter value contains double-quotes
  • The $let sets the note variable to either the note param value or the tid param value (if the note is blank)
  • <<note>> renders the result as wikitext content

Thank you, @EricShulman, your solution was exactly what I needed. Thank you @Charlie_Veniot also for responding. With this, I can finally begin my quest for world domination…

Folks, we warned you not to loose the Giffmex again! It’s on your heads!

1 Like