Is there a way to display a tab, in sidebar tabs, only if a condition if met?

Folks,

I believe I can hack the tabs macro, or perhaps $:/core/ui/SideBarSegments/tabs to test a condition before displaying a tab. eg; [all[tiddlers]tag[$:/mySideBarTab]limit[1]] so that tab only displays if there are any tiddlers with the $:/mySideBarTab tag, otherwise nothing appears.

However I am wondering if there is a way that does not alter a core tiddler, such as being able hide it altogether perhaps with CSS?

To be able to hide a core sidebar tab would be helpful, however what if I create a new one? There must be a way to conditionally display/hide the tab itself, not simply its content.

Your thoughts?

Ore perhaps this is an enhancement needed in the core tabs macros(s)

1 Like

The easiest way to do this is to locate the shadow tiddlers that have a tag of
$:/tags/SideBar or $:/tags/MoreSideBar and just remove that tag from the tabs you want to hide.

Alternatively, to make this more centrally configurable, we could change two shadow tiddlers:
$:/core/ui/SideBarSegments/tabs and $:/core/ui/SideBar/More
and in each, change the tabsList parameter in the tabs macrocall by adding
-[enlist{$:/config/HideSideBarTabs}] and -[enlist{$:/config/HideMoreSideBarTabs}], respectively.

Then, to hide tabs, you just enter a space-separated list of titles into the appropriate config tiddler; e.g.,
enter $:/core/ui/SideBar/Tools into $:/config/HideSideBarTabs to hide the “Tools” tab,
or enter $:/core/ui/MoreSideBar/Orphans into $:/config/HideMoreSideBarTabs to hide the “Orphans” tab.

This second method could easily be added to the core, and would only have an effect when the corresponding $:/config/… tiddler is defined. In this way, once those two minor core changes are made, no further changes to core tiddlers are needed in order to hide any of the default tabs.

-e

3 Likes

Eric thanks for outlining these approaches but little more is needed to take this from a manual step to an automatic conditional step, particularly one based on the result of a filter, and not requiring a “trigger”.

As in my example I want a tab to only appear, if at least one tiddler, has being tagged with a nominated tag. eg; If more than one tiddler is tagged “$:/tags/indicator” then and only then display a tab in the sidebar about “indicators”. Typically this demands a trigger to add the $:/tags/SideBar tag.

Conditional CSS that can hide a tab still seems the best approach but I do not know how to do it. eg Custom data-styles

For an ongoing solution, I think a hybrid of your solution and another may provide an answer. I am thinking of two filters both point to a “cascade”, one cascade is include, the other exclude. Then as the list of tabs is generated [tag[$:/tags/SideBar]] it also uses the cascade to look for additional filters the will generate a list of additional tabs to “include” or “exclude”.

Actually the idea of a standard mechanism or code pattern to specify, “included and excluded” titles in a filter, via a cascade of filters, allowing new filter conditions to be added without core tiddler changes would be helpful.

Thanks for your thoughts I will continue looking.
Any new ideas welcome.

One of the most heated issue threads, eventually resolved, was #1066 Search results in a tab of the Sidebar. This indirectly dealt with the OP here and there were demos made so it has, presumably, been solved previously.

@twMat I see this thread is from 2014 and are reading through it;

This does make me think of a code pattern I use elsewhere, allowing a tiddler to have a display-condition field which contains a filter. It seems if such a field was used if it exists before rendering the tab would be a good approach. To me we could do this for a range of applications.

Of course this would need to be built into the tabs macro, similarly the TOC macros etc…

This does suggest to me I may need to alter/replace the current sideBar tabs code.

@twMat I do see what your were trying to achieve in that GitHub issue, here we concur.

Unless?

Thanks to the repies here I have an idea, which I will place in a new reply.

Are you looking for something like this?
https://tiddlywiki.com/#Debugging%20Stylesheets:[[Debugging%20Stylesheets]]%20%24%3A%2Fsnippets%2FDebugStylesheets

What if we solve this by Creating a new enhanced version of the current toolbar visibility method, and add to the tabs process?

The display of buttons on toolbars is controlled by the creation of a tiddler of the form
$:/config/ViewToolbarButtons/Visibility/tiddlername containing show or hide.

  • So we can use $:/config/SideBarTabs/Visibility/tiddlername
  • Replace a simple test of this value, with a transclusion, That is the visibility mechanism can use a condition to be provided to generate the resulting show/hide value.
  • Then we add it to the tabs mechanism.

ie Since we want to avoid needing to edit core tiddlers we could use a mechanism similar to the toolbar button visibility tiddlers, but not just yes/no or show/hide allow conditions to be provided. eg; {{{ [{$:/config/design-mode}match[yes]then[show]else[hide]] }}}

How to achieve?

  • Wikify the contents of the visibility tiddlers before using the result as a test eg show/hide. The default show/hide values will continue to work.
  • provide a mechanism when toggling the visibility if the value is not yes or no.
    • yes no maybe? where maybe is use a condition
    • if yes or no is set save the condition in the visibility tiddler.

thoughts?

1 Like