Showing specific text depending on where the text is being shown?

While working on some older projects, I found a WIP that I set aside when I couldn’t quite figure it out, and figured I could turn to the community for a possible solution.

The specific question is, how would you show specific text only in the storyriver tiddler is and only show specific text in the sidebar.

For example, lets say I have a tiddler titled ‘Placeholder’ with the tags “$:/tags/SideBar” and I want it to show Hello only in the sidebar and if it is in the storyriver, it should show the text “Goodbye”.

So, if both the Placeholder sidebar tab is selected AND the tiddler is open in the storyriver, the story river tiddler should show “Goodbye” and the sidebar should only show “Hello” but not show both in either of them.

Unfortunately I’ve only figured out how to show the text of both if they are open in their respective places using:

<$list filter="[[$:/StoryList]contains[Placeholder]]">

Hello

</$list>

<$list filter="[prefix[$:/state/tab/sidebar]text[Placeholder]]">

Goodbye

</$list>

Is there a different way I should be approaching this? :thinking:

In the story you will find both currentTiddler and StoryTiddler are set to the current tiddler. however currentTiddler often changes inside lists and other TiddlyWiki script. In the sidebar tabs however neither of these variables are set but currentTab is.

You can test for currentTab and even set currentTiddler to this if you want in the side bar tabs.

Is that enought for you to go on?

[Edited] Note the thisTiddler variable returns the title of the tiddler in which <<thisTiddler>> is typed. I think of it as the code tiddler.

  • Remember you can set caption and icon fields for tiddlers and to use in tabs.

I’m not sure I follow :sweat_smile: Do you mean that I would wrap the list widgets inside a parent list widget that checks if it is set to the currentTiddler or currentTab? If so, I’m not sure how you would achieve that in a formula.

Would you be able to reword that?

I GOT IT!

<$list filter="[variable<currentTiddler>match[Journal]]">

WOW

</$list>

<$list filter="[variable<currentTab>match[Journal]]">

hello

</$list>

it took me a second to figure out how to use the variable operator but this works! Thank you @TW_Tones :grin:

Drop this on any wiki and import then view it in the story, and see it in the side bar.

It illustrates the values of the variables in each place. And you can use these in if, and filters to alter what happens where.

Side Bar tab.json (556 Bytes)

This is a little different to your interpretation above

1 Like

Your approach may not work if you rename the tiddler. Mine should.

For Visibility of the tiddler I shared

<% if [all[current]match<thisTiddler>] %>

Do this in the story

* currentTiddler/storyTiddler = <<currentTiddler>>/<<storyTiddler>>
* CurrentTab = <<currentTab>>
<%else%>

Do this out of the story currentTab

* currentTiddler/storyTiddler = <<currentTiddler>>/<<storyTiddler>>
* CurrentTab = <<currentTab>>

<%endif%>

[all[curent].. is equivalent to `[…

You’re right, renaming breaks it without something like Relink, and you can’t really call the {!!title} or <currentTiddler> because of the way the filter is setup :sweat_smile:

however, borrowing from your solution, if I use <thisTiddler>, I can resolve this issue!

<$list filter="[variable<currentTiddler>match<thisTiddler>]">

WOW

</$list>

<$list filter="[variable<currentTab>match<thisTiddler>]">

hello

</$list>

I will need to play around with the if then else syntax more, but it certainly looks cleaner when typed out. I guess old habits die hard though

I think its more meaning full if you used the following filter rather than using variable;

[all[current]match<thisTiddler>] when the currentTiddler = thisTiddler

[all[current]!match<thisTiddler>] when the currentTiddler Not ! = thisTiddler

Of it could be as simple as [<currentTab>] as unless this has a value its not in the tabs.

The good thing about the <%if conditionfilter %> <%else%> is it only asks one question.

<$list filter="[variable<currentTiddler>match<thisTiddler>]">

FYI, variable isn’t a core filter operator, so (unless you’ve installed a non-standard plugin) it’s being ignored in both instances. But conveniently, all you really need is [<currentTiddler>match<thisTiddler>] and [<currentTab>match<thisTiddler>], so your code works anyway.

2 Likes

Oh, whoops, I must of mistaken it for variables, thank you! lucky accident that it still works lol

1 Like

My first thought would be to do this with CSS:

In a $:/tags/Stylesheet tiddler or a <style> tag:

.story-only {display: none;}
.tc-story-river .story-only {display: unset;}
.sidebar-only {display: none;}
.tc-sidebar-scrollable .sidebar-only {display: unset;}

And then you can just do this:

title: Placeholder 2
tags: $:/tag/SideBar

@@.story-only
Hello
@@

@@.sidebar-only
Goodbye
@@

It also works @@.story-only;just fine-and-dandy@@ @@.sidebar-only;well@@ inline.

or this:

title: Placeholder
tags: $:/tags/SideBar

<div class="story-only">Hello</div>
<div class="sidebar-only">Goodbye</div>

<p>
  It also works 
  <span class="story-only">just fine-and-dandy</span>
  <span class="sidebar-only">well</span>
  inline.
</p>

Obviously, if rendering these sometimes-hidden sections requires a great deal of resources, then this technique could be wasteful. But similar things work well for me in other circumstances.

1 Like