State tiddler dependent on tiddler title

Hello all,

Below is a ViewTemplate tiddler that I use for all tiddlers tagged with DXQTH. QTH is an amateur radio term for listening post basically. So in my case, each location is where I’ve done some shortwave listening and logged stations. This view template using dynamic tables to show all logs of a given class heard from each location. The title of each QTH tiddler is the address for that QTH. This all works great as it is.

However, I would like to change this so that the state tiddler for the class selection is unique for each QTH. Right now, $:/state/qthviewclass is used for all. The reason I would like to do this is because I don’t always listen to the same class of station from each location. I would also like the state tiddler used for the dynamic tables to be unique per QTH. I’ve tried various ways I found through search here, but I haven’t found the right combination that would work. Any suggestions on the right way to go?

Thanks in advance!

\define is-dx-qth()
[<currentTiddler>tag[DXQTH]]
\end

<$set name="thisqth" value=<<currentTiddler>> >

<$list filter=<<is-dx-qth>> >

<fieldset style="margin-bottom: 5px;">
  <legend style="font-size: 0.8em; margin-left: 1em; padding: 0 0.5em 0 0.5em;">Enter Search Criteria</legend>
  <table class="table-borderless" style="font-size: 0.85em; accent-color: CadetBlue;">
    <tr>
      <td>Class:&emsp;</td>
      <td><$radio tiddler="$:/state/qthviewclass" field="text" value="MWBC"> MWBC</$radio></td>
      <td><$radio tiddler="$:/state/qthviewclass" field="text" value="NDB"> NDB</$radio></td>
      <td><$radio tiddler="$:/state/qthviewclass" field="text" value="FM"> FM</$radio></td>
      <td><$radio tiddler="$:/state/qthviewclass" field="text" value="SWBC"> SWBC </$radio></td>
      <td><$radio tiddler="$:/state/qthviewclass" field="text" value="NOAA"> NOAA </$radio></td>
      <td><$radio tiddler="$:/state/qthviewclass" field="text" value="AirVHF"> AirVHF </$radio></td>
      <td><$radio tiddler="$:/state/qthviewclass" field="text" value="Aircraft"> Aircraft </$radio></td>
      <td><$radio tiddler="$:/state/qthviewclass" field="text" value="Time"> Time </$radio></td>
      <td><$radio tiddler="$:/state/qthviewclass" field="text" value="TimeV"> TimeV </$radio></td>
      <td><$radio tiddler="$:/state/qthviewclass" field="text" value="Spy"> Spy </$radio></td>
      <td><$radio tiddler="$:/state/qthviewclass" field="text" value="WeaV"> WeaV </$radio></td>
      <td><$radio tiddler="$:/state/qthviewclass" field="text" value="WeaD"> WeaD </$radio></td>
      <td style="padding-left: 20px;">Total Logs: <$count filter="[tag[DXLog]dx-qth<thisqth>]"/></td>
    </tr>
  </table>
</fieldset>

<fieldset style="margin-bottom: 10px; padding: 5px 10px 0 10px; display: grid; font-size: 0.8em;">
  <legend style="margin-left: 1em; padding: 0 0.5em 0 0.5em;">Logs</legend>
    <table class="table-borderless" style="width: 20%; margin: 0;">
      <tr>
        <td>Class: {{$:/state/qthviewclass}}</td>
        <td>Logs Returned = <$count filter="[tag[DXLog]dx-qth<thisqth>dx-class{$:/state/qthviewclass!!text}]"/></td>
        <td>
          <$button class="tc-btn-invisible" tooltip="Reset Pagination">{{$:/core/images/refresh-button}}
            <$action-setfield $tiddler="$:/keepstate/dynamictables/$:/state/qthview/pagination/page-number" text="1" />
            <$action-setfield $tiddler="$:/keepstate/dynamictables/$:/state/qthview/pagination/entry-per-page" text="25" />
          </$button>
        </td>
      </tr>
    </table>
    <<table-dynamic filter:"[tag[DXLog]dx-qth<thisqth>dx-class{$:/state/qthviewclass!!text}]" fields:"dx-date dx-time dx-freq-khz dx-exact-khz dx-station dx-slogan dx-sinpo dx-language dx-mode dx-tx-location dx-state dx-country" pagination:"yes" editButton:"no" sortOp:"sortan" stateTiddler:"$:/state/qthview/pagination">>
</fieldset>

</$list>

</$set>

Is this the sort of thing you’re looking for?

\define is-dx-qth() [<currentTiddler>tag[DXQTH]]

<$let
	thisqth=<<currentTiddler>>
	state=`$:/state/qthviewclass/$(thisqth)$`
	class={{{ [<state>get[text]] }}}
	table-state=`$:/state/qthview/$(thisqth)$/pagination`
>
<$list filter=<<is-dx-qth>> >

<fieldset style="margin-bottom: 5px;">
  <legend style="font-size: 0.8em; margin-left: 1em; padding: 0 0.5em 0 0.5em;">Enter Search Criteria</legend>
<$tiddler tiddler=<<state>>>
  <table class="table-borderless" style="font-size: 0.85em; accent-color: CadetBlue;">
    <tr>
      <td>Class:&emsp;</td>
      <td><$radio field="text" value="MWBC"> MWBC</$radio></td>
      <td><$radio field="text" value="NDB"> NDB</$radio></td>
      <td><$radio field="text" value="FM"> FM</$radio></td>
      <td><$radio field="text" value="SWBC"> SWBC </$radio></td>
      <td><$radio field="text" value="NOAA"> NOAA </$radio></td>
      <td><$radio field="text" value="AirVHF"> AirVHF </$radio></td>
      <td><$radio field="text" value="Aircraft"> Aircraft </$radio></td>
      <td><$radio field="text" value="Time"> Time </$radio></td>
      <td><$radio field="text" value="TimeV"> TimeV </$radio></td>
      <td><$radio field="text" value="Spy"> Spy </$radio></td>
      <td><$radio field="text" value="WeaV"> WeaV </$radio></td>
      <td><$radio field="text" value="WeaD"> WeaD </$radio></td>
      <td style="padding-left: 20px;">Total Logs: <$count filter="[tag[DXLog]dx-qth<thisqth>]"/></td>
    </tr>
  </table>
</$tiddler>
</fieldset>

<fieldset style="margin-bottom: 10px; padding: 5px 10px 0 10px; display: grid; font-size: 0.8em;">
  <legend style="margin-left: 1em; padding: 0 0.5em 0 0.5em;">Logs</legend>
    <table class="table-borderless" style="width: 20%; margin: 0;">
      <tr>
        <td>Class: <<class>></td>
        <td>Logs Returned = <$count filter="[tag[DXLog]dx-qth<thisqth>dx-class<class>]"/></td>
        <td>
          <$button class="tc-btn-invisible" tooltip="Reset Pagination">{{$:/core/images/refresh-button}}
            <$action-setfield
		$tiddler=`$:/keepstate/dynamictables/$(table-state)$/page-number` text="1" />
            <$action-setfield
		$tiddler=`$:/keepstate/dynamictables/$(table-state)$/entry-per-page` text="25" />
          </$button>
        </td>
      </tr>
    </table>
    <$macrocall $name=table-dynamic
	filter="[tag[DXLog]dx-qth<thisqth>dx-class<class>]"
	fields="dx-date dx-time dx-freq-khz dx-exact-khz dx-station dx-slogan dx-sinpo dx-language dx-mode dx-tx-location dx-state dx-country"
	pagination="yes"
	editButton="no"
	sortOp="sortan"
	stateTiddler=<<table-state>>
    />
</fieldset>

</$list>
</$let>

Here, I defined two state tiddlers (and the <<class>> variable, derived from <<state>>) as variables at the beginning of the tiddler, using substituted attribute values (note the backticks!) to generate a state title that includes <<thisqth>>/the current tiddler. Then I replaced all the hard-coded tiddler title references with the variables (using $tiddler to temporarily redefine the <<currentTiddler>> variable around the block of $radio widgets, so you don’t have to set tiddler=<<state>> on each individual $radio.) Finally, since your dynamic tables keepstates also included the name of the tiddler used as the dynamic table’s stateTiddler, I used two more substituted attribute values to define the $action-setfield $tiddler=... titles.

I think I caught all the spots that needed replacements, but it’s possible I’ve made a typo or two. If so, I hope the general technique is clear enough that you can catch it.

2 Likes

@etardiff

Thank you very much for the solution! That worked just how I wanted it to. I think the thing I was missing was the use of the tiddler widget.

1 Like

I’m glad it worked for you!

It occurred to me very belatedly that you could further simplify your $radio widgets by nesting them in a $list. If you like, you can replace

<$tiddler tiddler=<<state>>>
  <table class="table-borderless" style="font-size: 0.85em; accent-color: CadetBlue;">
    <tr>
      <td>Class:&emsp;</td>
      <td><$radio field="text" value="MWBC"> MWBC</$radio></td>
      <td><$radio field="text" value="NDB"> NDB</$radio></td>
      <td><$radio field="text" value="FM"> FM</$radio></td>
      <td><$radio field="text" value="SWBC"> SWBC </$radio></td>
      <td><$radio field="text" value="NOAA"> NOAA </$radio></td>
      <td><$radio field="text" value="AirVHF"> AirVHF </$radio></td>
      <td><$radio field="text" value="Aircraft"> Aircraft </$radio></td>
      <td><$radio field="text" value="Time"> Time </$radio></td>
      <td><$radio field="text" value="TimeV"> TimeV </$radio></td>
      <td><$radio field="text" value="Spy"> Spy </$radio></td>
      <td><$radio field="text" value="WeaV"> WeaV </$radio></td>
      <td><$radio field="text" value="WeaD"> WeaD </$radio></td>
      <td style="padding-left: 20px;">Total Logs: <$count filter="[tag[DXLog]dx-qth<thisqth>]"/></td>
    </tr>
  </table>
</$tiddler>

with

  <table class="table-borderless" style="font-size: 0.85em; accent-color: CadetBlue;">
    <tr>
      <td>Class:&emsp;</td>
    <$list filter="MWBC NDB FM SWBC NOAA AirVHR Aircraft Time TimeV Spy WeaV WeaD" variable="value">
      <td><$radio tiddler=<<state>> field="text" value=<<value>>> <<value>></$radio></td>
    </$list>
      <td style="padding-left: 20px;">Total Logs: <$count filter="[tag[DXLog]dx-qth<thisqth>]"/></td>
    </tr>
  </table>

Since the label used for each $radio matches its value when selected, we can use a $list to generate one table cell per $radio, which will be automatically populated with the correct values. This also lets us remove the $tiddler widget and replace it with a single tiddler=<<state>> in the list template.

Ooh. Very interesting. I may have to give that a whirl! Thanks.