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

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.