[TW5] Tabs Based on the Existence of a Field?

117 views
Skip to first unread message

Zaphod Beeblebrox

unread,
Oct 1, 2016, 10:40:01 PM10/1/16
to TiddlyWiki
I think I may really be going out on a limb, here, but I thought I'd come and ask, just in case this might be possible.

I'd like to have a set of tabs, each one transcluding a tiddler with some content in it, but each tab's appearance would be conditional on whether or not a field existed in the current tiddler.

In other words:

<<tabs tiddler1 tiddler2 tiddler3>>
(but only if field1, field2, field3 existed in the tiddler)

If only field1 and field3 exist, then

<<tabs tiddler1 tiddler3>>

The only method I know of is using the $list widget to check for the existence of a field, but I can't insert a $list into the tabs widget, can I?

Anyone know of an alternate solution?

--Zaphod

Tobias Beer

unread,
Oct 2, 2016, 4:03:40 AM10/2/16
to tiddl...@googlegroups.com
Hi Zaphod,

As things stand, I think you will have to clone the core tabs macro
and write your own that does what you want.

If you want to define the following for each tab in one go
  • the field:
    based on which to show the tag
  • the content reference:
    that you actually want to show, may even be a template
For one, it doesn't seem like you actually want to use any kind of filter,
but always define the tabs as titles.

You could devise a "tabs" parameter for the macro like so:

"[[field1:ref1]] [[field2:||ref2]] [[field3:ref3]]"

for example:

"[[title:Tiddler Foo]] [[planet:||$:/_my/templates/planet-data]] [[jedi:The Force]]"

Using the title field as the decision maker kinda says: always show this tab.
Then you could use the filter tobibeer/split to take each tab definition apart at the colon
and then use reveals to decide whether or not to show a tab,
whereas any reference starting || would be transcluded as a template,
rather than a reference "as is".

Other than that, I don't know if Alberto Molina's BottomTabs or MagicTabs
provided some conditional logic to decided when to show a tab.
I don't remember it did, though.

Best wishes,

Tobias.

Jed Carty

unread,
Oct 2, 2016, 4:15:12 AM10/2/16
to TiddlyWiki
You may be able to do something like this, it works on tiddlywiki.com:

<$set filter='[tag[TableOfContents]fields[]]' name=FieldsForTabs>

<$macrocall $name=tabs tabsList=<<FieldsForTabs>>/>

</$set>

Jeremy Ruston

unread,
Oct 2, 2016, 4:17:05 AM10/2/16
to tiddl...@googlegroups.com
Hi Zaphod

I think there’s an even simpler way to accomplish this:

<<tabs "[[tiddler1]has[field1]] [[tiddler2]has[field2]] [[tiddler3]has[field3]]”>>

Does that do what you need?

Best wishes

Jeremy.

--
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+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/1dd8416e-f98a-4ff0-b3f3-157b3612eada%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tobias Beer

unread,
Oct 2, 2016, 8:01:51 AM10/2/16
to tiddl...@googlegroups.com
Hi Jeremy,
 
I think there’s an even simpler way to accomplish this:

<<tabs "[[tiddler1]has[field1]] [[tiddler2]has[field2]] [[tiddler3]has[field3]]”>>

Does that do what you need?

I believe this won't work, since Zaphod wants to test
for the presence of a field at the tiddler where the tabs macro is used
rather than at the tiddler being the tab.

While it doesn't look pretty at all, this seems to work:

<<tabs "
[
<currentTiddler>has[foo]addsuffix[Foo]removeprefix<currentTiddler>]
[
<currentTiddler>has[bar]addsuffix[Bar]removeprefix<currentTiddler>]
[
<currentTiddler>has[baz]addsuffix[Baz]removeprefix<currentTiddler>]
”>>

Whereas Foo, Bar, Baz would be the tiddlers we want displayed as tabs.

I think a prettier version would look more like:

<currentTiddler>has[foo]set[Foo]or[Bar]]

Meaning: Whatever the input titles, if there are any, return Foo and if there are none at all, return Bar.

Addendum:

I have created a ticket for the above:

set and or filter operators
https://github.com/Jermolene/TiddlyWiki5/issues/2591

Best wishes,

Tobias. 
Reply all
Reply to author
Forward
0 new messages