This is a stripped-down version of a single section of Grok TiddlyWiki, optimized for fast loading and readability by search engines. Some features are missing.

For the full Grok TiddlyWiki experience, please visit the wiki version of this page.

Ex:ConditionalProcedureContinued/answer

 10th October 2024 at 8:16am

The trick here (useful in a wide variety of situations) is to use a $list widget with a filter consisting of a “tiddler list” of the items you want to loop over, here the field names. We'll assign these to the variable field, and pass that variable's value as the parameter to the contact-info-item procedure:

\procedure contact-info-item(field)
  <% if [all[current]has<field>] %>
    <li>
      ''<<field>>'':
      <$transclude $field=<<field>>/>
    </li>
  <% endif %>
\end

<ul>
  <$list filter="email phone family manager" variable="field">
    <$transclude $variable="contact-info-item" field=<<field>> />
  </$list>
</ul>

One can imagine taking this even further, getting the actual procedure call down to a single line:

\procedure contact-info-item(field)
  <% if [all[current]has<field>] %>
    <li>
      ''<<field>>'':
      <$transclude $field=<<field>>/>
    </li>
  <% endif %>
\end

\procedure contact-info(fields)
  <ul>
    <$list filter=<<fields>> variable="field">
      <$transclude $variable="contact-info-item" field=<<field>>/>
    </$list>
  </ul>
\end

<<contact-info "email phone family manager">>

...but at some point, adding additional layers of abstraction makes your wikitext harder to understand, rather than easier.

Go to question: Ex:ConditionalProcedureContinued