How to hide an empty parameter?

Hi,

I’m trying to find a way to hide an empty parameter but I can’t find one, or maybe, I’m just not understanding it correctly.

An example code:

  1. In a Template called `infoboxA I have this:
<ul><$parameters param1="" param2="" param3="">
<li>Param1: <<param1>></li>
<li>Param2: <<param2>></li>
<li>Param3: <<param3>></li>
</$parameters></ul>
  1. Then in Test page I have this:
<$transclude $tiddler="infoboxA"
  param1="This is Parameter 1"
  param2="This is Parameter 2"
/>
  1. The result is:
* Param1: This is Parameter 1
* Param2: This is Parameter 2
* Param3:

What I would like to achieve is if a param is empty, like in the example above it’s param3, it wouldn’t show.

Something like:

<ul><$parameters param1="" param2="" param3="">
{{hide-if-empty}}<li>Param1: <<param1>></li>{{/hide-if-empty}}
{{hide-if-empty}}<li>Param2: <<param2>></li>{{/hide-if-empty}}
{{hide-if-empty}}<li>Param3: <<param3>></li>{{/hide-if-empty}}
</$parameters></ul>

And the output will be:

* Param1: This is Parameter 1
* Param2: This is Parameter 2

Since this is the first time I dived into the this, I would like to keep it simple at first so I can follow. (I only used TiddlyWiki for note taking before.) Is it possible to achieve while keeping it as simple as possible?

Thank you!

Welcome to the TiddlyWiki community, @youronlyone!

In infoboxA, you can use the <%if [somefilter] %>...<%endif%> Conditional Shortcut Syntax, like this:

<ul><$parameters param1="" param2="" param3="">
<%if [<param1>!match[]] %><li>Param1: <<param1>></li><%endif%>
<%if [<param2>!match[]] %><li>Param2: <<param2>></li><%endif%>
<%if [<param3>!match[]] %><li>Param3: <<param3>></li><%endif%>
</$parameters></ul>

Notes:

  • The [<param1>!match[]] uses filter syntax to test the value of <param1> to see if it is not an empty string.
  • If the filter result is not empty, then the content within the `<%if …%>…<%endif%> is rendered.
  • The “conditional shortcut syntax” is actually a more compact form of the $list widget, which would be written like this:
<$list filter="[<param1>!match[]] +[first[]]" variable="condition">
   <li>Param1: <<param1>></li>
</$list>

enjoy,
-e

3 Likes

Thank you very much! Perfect!

And thank you for the link… I definitely was searching for the wrong keywords. ^_^;;