Out of curiosity, is there a way to define a class based on an available tag or field?

Let’s say I have two tags: $:/tag/type-1 and $:/tag/type-2. A tiddler will have one or the other tag, but both tags. I would like to be able to define a class to a span based on the tag.

For example, see my code below:

<$list filter="[tag[$:/tag/type-1]]">
  <span class="tc-tiddler-class class-type-1">
</$list>
<$list filter="[tag[$:/tag/type-2]]">
  <span class="tc-tiddler-class class-type-2">
</$list>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</span>

The problem with using this approach is I get the output that looks like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span>

Because the </span> tag is not nested inside any of the <$list> widgets, it appears as part of the output.

To avoid that problem, I end up writing my code like this:

<$list filter="[tag[$:/tag/type-1]]">
  <span class="tc-tiddler-class class-type-1">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  </span>
</$list>
<$list filter="[tag[$:/tag/type-2]]">
  <span class="tc-tiddler-class class-type-2">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  </span>
</$list>

Is there a more efficient way?

I don’t know about “more efficient” but…

<span class={{{ [<currentTiddler>tag[X]then[class-X]] :else[<currentTiddler>tag[Y]then[class-Y]] }}}>
test
</span>

You could try computing the value using a macro.

1 Like

Thanks, helps a lot. Now I don’t have to double up on all my code.

1 Like

It doesn’t really scale well, though. Perhaps @saqimtiaz/@Mark_S/@EricShulman could advise on a more efficient mechanism that would scale better to N-classes.

Perhaps a not is missing?