How to create a Switchable view-template and edit-template for History-Monthly-View

This is a Modified History-Monthly-View which was shared by Mohammed sometime back. I modified it to be displayed as a table with links in the left column and tiddler body view-template in the right column (based on the template Alternate viewtemplate). This modification was done based on this solution by etardiff.

image

This is another modified version where links are shown in the left column and tiddler edit-template in the right column (based on the template Alternate editor-Editor).

Then I tried to combine these two here - make the view-template and edit-template of tiddler body to be displayed as needed using a toggle button. I used search-replace operator to do this. But it was not working. Here is the relevant part of the code used. What might be going wrong.

\define replace-template()
[[History-Monthly-View-Table]search-replace[Alternate viewtemplate],[Alternate editor-Editor]]
\end

\define replace-editor()
[[History-Monthly-View-Table]search-replace[Alternate editor-Editor],[Alternate viewtemplate]]
\end

<$list filter="[<stateTid>get[year]]" variable=null emptyMessage=<<initialize>> >

<$button actions=<<replace-template>> >
Replace template
</$button>


<$button actions=<<replace-editor>> >
Replace editor
</$button>

<div>
<$let current=<<currentTiddler>>>
<table class="styled-table">
 <tr>
<td style="vertical-align:top; overflow: auto;width: 50%;">
<!-- UI to select year and month -->
<<select-year>>&nbsp;<<select-month>>

<!--Results for that Year - Month -->
<<tiddlers-list-monthly>>
  </td>
    <td style="vertical-align:top; overflow: auto; display: block; height: 100vh;overflow-y: scroll;">
<$list filter="[{!!display}]">

!! <$link/>
<$transclude mode="block" tiddler="Alternate viewtemplate" />
</$list>
  </td>
  </tr>
</table>
</$let>
</div>
1 Like

Your replace-template and replace-editor macros don’t currently define actions, just filters, so clicking the button doesn’t actually “do” anything. You’d need to use an action widget - in this case, probably action-setfield.

Also note that your filter isn’t doing what you’d want it to. Here’s what you have:

[[History-Monthly-View-Table]search-replace[Alternate viewtemplate],[Alternate editor-Editor]]

Square brackets around a title (like [History-Monthly-View-Table]) indicate a literal value, so search-replace is looking for “Alternate viewtemplate” in “History-Monthly-View-Table”—which doesn’t contain that string, of course, so no replacement occurs. To target the text field of the History-Monthly-View-Table tiddler, you’d need {History-Monthly-View-Table}.

However…

Rather than editing your viewtemplate every time you want to switch views, I’d recommend an alternate approach.

\define switch-template()
<$action-listops $tiddler="$:/state/History-Monthly-View-Table/view" $field="text" $subfilter="+[toggle[edit],[view]]" />
\end

<$button actions=<<switch-template>> >
Switch template
</$button>

<$transclude mode="block" tiddler={{{ [[$:/state/History-Monthly-View-Table/view]text[edit]then[Alternate editor-Editor]] ~[[Alternate viewtemplate]] }}} />

Here, we’re using a button to set the text field of a state tiddler, instead of editing one of your core templates.

  • toggle lets us switch between two (or more) values (though note that you’ll have to click it once to set the initial value.)
  • We can use filtered transclusion to choose the $transclude template based on the value of the state tiddler. In this case, ~[[Alternate viewtemplate]] is the “fallback” value, which will be used if the state tiddler doesn’t exist.
  • Using a state tiddler like this means that you won’t “dirty” your wiki every time you switch views, and it should be slightly more efficient than running a search-and-replace.
1 Like

Thank you for the help. Thats working.

I knew that there would be a better method than what I was using. I just tried an idea that came to my mind. I think I can learn from this solution and modify some of the other hacks I have done in the past.

1 Like

It was a very creative approach, honestly—not one I’d ever considered before!

1 Like

Perhaps the title of this topic should be changed to reflect its content? @arunnbabu81

@TW_Tones I am not sure how to rename the title. How to create a Switchable Table for History-Monthly-View.Is that the right title?

If you have some ideas, feel free to edit the title.

Perhaps “combining the view-template and edit-template” which seems to be the solution you were after.

Also this looks similar to your requirements, I have in the past enabled the view toolbar in a similar view so you can edit the tiddler if needed. Here is an earlier post

  • Some call this an outliner

How to create a Switchable view-template and edit-template for History-Monthly-View

How about this?

I had seen Outlier by Mark when I started using TW. I didn’t use it much then. I am away from my desktop at the moment. Looks like I will have to take a look at it once more now that I understand TW things a little more. Thanks for the suggestion @TW_Tones

1 Like

@TW_Tones I remember something similar to streams created by Mark sometime back. It’s name was similar to Outlier. After trying out the json of the Outlier shared in the Google groups, I have a doubt whether this is the same one or not. Do you have any idea?

No sorry. Not like streams.

@TW_Tones I was talking about Notowritey.
https://marxsal.github.io/various/notowritey.html

I modified the Outlier macro by Mark to add the above given switchable template by @etardiff

Here is the demo

Oh, another approach is @Mohammad’s section editor which divides the tiddler by headings for the purpose of editing.

  • Yes, Outlier is eminently customisable.

I do use section editor in my wikis because it helps to organise tiddler contents (and looks good also) without actually adding any extra contents to the tiddler text field.

A post was merged into an existing topic: Unusual layout: is it possible?