Sidebar vs Story River tiddler rendering

Is there a way to display a given tiddler differently depending on whether it is opened in the story river vs the sidebar? For example, I have tiddler that will list the results of a search in a dynamic table, but I’d like that same tiddler to display the results in a simple list when in the sidebar.

Thanks in advance.

G’day,

Take a look at the tiddler called $:/core/ui/SideBar/Open

You’ll notice that your tiddler in the sidebar won’t show up in that “…/Open” tiddler unless in the story river.

From that “…/Open” tiddler, let’s grab this: [list<tv-story-list>]

In your tiddler’s text, add: {{{ [list<tv-story-list>] }}}

That gives a nice list of tiddlers that are currently open in the story river.

Finally, in your tiddler, replace {{{ [list<tv-story-list>] }}} with

<$list filter="[list<tv-story-list>match<currentTiddler>]" >
Hey, I'm open in the story river
</$list>
<$list filter="[list<tv-story-list>!match<currentTiddler>]" >
Hey, I'm not open in the story river
</$list>

Please, follow-up with any questions. Cheers !

EDIT (so the second filter only results in one item):

<$list filter="[list<tv-story-list>match<currentTiddler>]" >
Hey, I'm open in the story river
</$list>
<$list filter="[list<tv-story-list>!match<currentTiddler>join[]]" >
Hey, I'm not open in the story river
</$list>

EDIT Deux (I’ll let you guess why):

<$list filter="[list<tv-story-list>match<currentTiddler>]" >
Hey, I'm open in the story river
</$list>
<$list filter="[list<tv-story-list>!match<currentTiddler>then<currentTiddler>]" >
Hey, I'm not open in the story river
</$list>

Now that I’m done celebrating NY Rangers win over TB Lightning …

EDIT Trois (Handling no tiddlers open at all in the story river)

<$list filter="[list<tv-story-list>match<currentTiddler>]" >
Hey, I'm open in the story river
</$list>
<$list filter="[list<tv-story-list>else[none open]!match<currentTiddler>join[]then<currentTiddler>] " >
Hey, I'm not open in the story river
</$list>

Depending on how your table is structured, you can have a lot of fun with CSS styles that change depending on whether the table is in the sidebar (nested inside the .tc-sidebar-header tag) or outside of it.

Here is some quick styles to only show the first column of each table row and have them formatted as a list, if the table is in the sidebar…

<table class="dynamic">
   <tr>
      <th>header</th>
      <th>header</th>
      <th>header</th>
      <th>header</th>
   </tr>
   <tr>
      <td>table cell</td>
      <td>table cell</td>
      <td>table cell</td>
      <td>table cell</td>
   </tr>
   <tr>
      <td>table cell</td>
      <td>table cell</td>
      <td>table cell</td>
      <td>table cell</td>
   </tr>
   <tr>
      <td>table cell</td>
      <td>table cell</td>
      <td>table cell</td>
      <td>table cell</td>
   </tr>
</table>

<style>
.tc-sidebar-header table.dynamic,
.tc-sidebar-header table.dynamic tr,
.tc-sidebar-header table.dynamic th,
.tc-sidebar-header table.dynamic td { border: none; }

.tc-sidebar-header table.dynamic th,
.tc-sidebar-header table.dynamic td:not(:first-child) { display: none; }

.tc-sidebar-header table tr td:first-child {
   display: block;
}

.tc-sidebar-header table tr td:first-child::before {
   content: "&#9733;&emsp;"
   
}

.tc-sidebar-header table tr td:first-child::after {
   content: " &mdash; list-item-style";
}
</style>

…which should give you something like the below image: normal table in the Story River, fancy list in the sidebar, without changing any of the table code.

4 Likes

Thank you gentlemen. I really appreciate the responses. I’ll give both methods a try.

If I understood the OP right, @HistoryBuff needs a way to detect whether the current tiddler is currently shown within the sidebar or the story river.
I think the best way would be to use the qualify macro, as it uniquely encodes the current location in the widget (?) tree.
Take e.g. the $:/core/ui/SideBar/Open tiddler on tiddlywiki.com. If you add the following code at the bottom

<$list filter="[<qualify>match[--1419714299]]">
This is the Sidebar, folks!
</$list>

you’ll see the message only in the Open tab of the sidebar, but not when the tiddler is rendered in the story river.
You can get the needed qualify “code” by just temporarily calling <<qualify>> somewhere in the tiddler.
Within the story river, the qualify string would be “–727386906” (note the two dashes which will become an en-dash in the wikified output).

Be aware that the qualify string changes when you rename the tiddler.

Have a nice day
Yaisog

PS: Alternatively, you could check for the existence of variables that are only defined in the sidebar, e.g. tabsState:

<$list filter="[<tabsState>!is[blank]]" emptyMessage="Rollin' on the River.">
Welcome to the Sidebar!
</$list>

This would work even after a rename.

It might be simplest to check the value of the storyTiddler variable.

\define sidebarView()
<!-- the things that go in the sidebar -->
\end

\define storyView()
<!-- story view-->
\end

<$list filter="[[storyTiddler]is[variable]" variable="null" emptyValue=<<sidebarView>> >
<<storyView>>
</$list>

Some useful FYI

  • In the sidebar the <<currentTiddler>> variable is not set,
  • however the <<currentTab>> variable is set.
  • StoryTiddler only shows when in story, so can be used to identify when in sidebar
    • See @saqimtiaz suggestion to respond differently to position
  • The transclusion variable can find the sidebar tiddler see attached
    • With this we can retrieve the current “code tiddler” without currentTiddler.
\define pipe() |
{{{ [<transclusion>split<pipe>nth[2]] }}}

a demo sidebar About SideBar tabs and values.json (753 Bytes)

Thanks very much to all. I really appreciate it and have learned some new things.

After playing around with each of the solutions, I’ve actually decided to take a different approach altogether. Since I was displaying the results of a custom search, I stored the search parameter in a state tiddler. It was then a simple matter to have two different lists based on that search parameter: one in the sidebar and one in the story river. The story river list uses Dynamic Tables from Shiraz with loads of detail whereas the sidebar list just has the titles of the results. I have a details button in the sidebar that pulls up the tiddler with the more detailed results when desired.

I went this route because it was an easier modification to existing tiddlers than the above suggestions because I was half way there anyway. However, I will keep these in my toolbox for later use for sure.

This group is awesome as always!

I’m sure @jeremyruston would like your approach. Content re-use from within different tiddlers instead of lumping it all together is the way of TW.
Have a nice day
Yaisog