Help to Qualify Checkbox State Field/Tiddler: A List-Based Expanding Content Menu

It graphically expands each of the listed tiddlers’ contents when you click each title (as opposed to just being a typical Table of Contents of titles)

Checkbox State Gets Created for the Global Macro Tiddler

This has come down to one thing: how to use a variable or parameter in order to specify a dynamic field name after two exclamation marks for the reveal state

I tried:

  • using the parameter
    • <$reveal state="!!$param$"
  • using a variable to concatenate the exclamation marks
    • value=’!!$param$’
    • or: value=’"!!$param$"’
    • <$reveal state="$(variable)$"
    • or: <$reveal state=".<.<variable.>.>"
  • removing the quotes brakes it

(The fields and field values get successfully created. But it is simply does not seem syntactic to use a param or var in order to dynamically create a field name.)

  • Note: It works if you manually enter one of the dynamically created fields:
    • state="!!st-210671450"

$:/tags/Macro

\define XPD-List(tagged:"help" stnam:"<<qualify st>>" headr:"2" clr:"grey" brd:"2")
<$set name="streveal" value='!!$stnam$' >
$stnam$
<$list filter="[tag[$tagged$]sort[title]] -[regexp:title[^Draft of \'.*]]">
<style type="text/css">
.exheading [type="checkbox"]{display:none;}
</style>
<div class="exheading" style="position:relative;">
<$checkbox field=$stnam$ checked="yes" unchecked="no">
<h$headr$ style="border-radius:4px; text-decoration:none; border:0px; margin-top:6px; margin-bottom:4px; padding-left:6px; padding-top:6px; padding-bottom:2px; background-color:$clr$;">
{{$:/core/images/unfold-button}}
<$transclude field="title" mode="inline"/> <<stnam>> <<streveal>> <span style="position: absolute; right: 10px; font-size:smaller;"><$link>[edit]</$link></span>
</h$headr$>
</$checkbox>
</div>
<div style="border-left:$brd$px solid $clr$; margin-left:25px; padding-left:30px; margin-right:15px;">
<$reveal state="$(streveal)$" type="match" text="yes">
<$transclude field="text" mode="block"/>
</$reveal>
</div>
</$list>
</$set>
\end
<<XPD-List tagged:"Wiki Related"  stnam:"<<qualify st>>" clr:"grey" brdr:"2" headr:"2">>

Just using a tag list, you can create menu/s of expanding sections. The expanding tiddlers are best kept quite short, like:

  • quick summaries
  • Title-based TOCs
  • multiple topical todo lists

In addition to changing the tag or filter, it can be useful to change the heading level.

Macro Params

I don’t get the procedures yet.

  • tagged: The list’s tag
  • stnam: State Tiddler Name
    • default is “<.<.qualify st>.>.” (minus the periods)
    • Might be helpful to declare at the time of the macro call
  • clr: color of the heading background, and the content’s left border
    • optional: default is “grey”
  • brdr: the content’s left border width
    • optional: default is 2, as in 2px
    • zero makes it go away

I use it multiple times with a CSS grid class:

<div class="gridivs">

<div>
! List-A Heading

<<macro call>>

</div>

<div>

! List-B Heading

<<macro call>>

</div>

</div>

Grid CSS

.gridivs {
display: grid;
grid-gap: 30px;
grid-auto-flow: row;
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
}

CSS Quirks

As this is right now, the divs do not allow putting the CSS styles anywhere but in the html elements. It might be a block and/or inheritance issue.

One possible approach is to use a filter, or the new function definitions

For example {{{ [all[current]get<fieldname>] }}} Will return the content of the field named in the “dynamic” variable fieldname.

Note $(streveal)$ returns the value of the variable “streveal”, but only in some specific cases, such as inside a \define macroname() or the new backtick parameter attributes.

  • As you did not show if your reveal was in a macro, I can not tell if you are using $(streveal)$ correctly.

Also most state parameters expect a “tiddler name”/“text reference” not the value itself. Have a look at the reveal state parameter on tiddlywiki.com

  • You either give a text reference OR
  • You can use stateTitle and stateField <<= I think this is what you need.
2 Likes

Could this be solved using another macro somehow?

All I need to do at this point is get some portion of “qualified” text substituted into that reveal statement - even if for instance it involves replacing larger portions of the reveal statement.

It really seems like it’s simply a syntax issue - some arrangement of quote marks. But I’m really stumped at this point.

Thanks.

I dont think you need a new macro, I think you need to fix your code.

At the moment you do this;

Then

Also Note I don’t think this is valid


Without me re-witing your code; Consider this

XPD-List(tagged:"help" state-prefix:"$:/state/xpd/">>

Change the parameter to state-prefix

<$set name=state-tiddler value=<<qualify state-prefix>> >

Now I ask do you really need to include another part to the state tiddler, from a field?, since it is already qualified?

With the above your reveal would look like this;

<$reveal state=<<state-tiddler>> type="match" text="yes">

“re-writing” the code: yeah unfortunately there are a couple precarious things about this from the get-go.

The whole thing is based on a checkbox, and checkboxes use a state field. I tried to use a “bound” “index”, but that’s also NOT a state tiddler. That’s a data field for a data tiddler.

The macro ends up successfully creating multiple qualified state fields on the content tiddler, for every list the tiddler is tagged in. It’s just that close to working.

As a sidenote: In conjunction with the list widget: I was thinking that the aspect of this being a checkbox is what made it work this way. (That’s a statement and a question.) It might definitely require a complete re-write for buttons.

Sometimes it helps if you state what you want clearly rather than what you need to fix, because there may be other approaches, and others may find it easier to answer.

  • Like have you tried the TOC expandable macro etc…?

Hopefully somebody will get jazzed about it when they try the macro such that they want to also get it to work.

(And if they do, it would be most gracious to post their findings here. Many thanks ahead of time.)

It works pretty well for the most part already. It’s just that last little inch.

I haven’t tested this in the context of your macro—and in fact, I suspect that it won’t work with your current stnam parameter, as @TW_Tones pointed out. But generally speaking I would try using a substituted attribute value like

<$reveal state=`!!$(param)$`

Note the backticks, not quote marks, around the attribute value.

Here’s a minimal example that should work inside or outside a macro. I added a button purely for ease of testing:

<$let field=<<qualify st>>>
<$button>toggle
<$action-listops $field=<<field>> $subfilter="+[toggle[yes]]" /> 
</$button>
<$reveal state=`!!$(field)$` type="match" text="yes">
shown
</$reveal>
</$let>

In this case, you won’t need stnam in your macro definition; instead, use <$let field=<<qualify st>>> as the first line of the macro.

1 Like

That did it! I will post the working macro.

Thanks so much.

Why should let work instead of set? let allows for multiple variables, but I’m only using one.

Perhaps let allows the qualify macro to be more individual to the instance?

1 Like

This syntax in incorrect. The syntax for assigning a value to a variable using the $set widget is:

<$set name="fieldName" value=<<qualify "showdit">>>

The state is now working beautifully! Thank you all so much for your help.

\define xpd-list(tagged:"help" hedr:"2" lefbrdr:"2" clr:"lightgrey")
<$let stfield=<<qualify xpd>>>
<$list filter="[tag[$tagged$]sort[title]] -[regexp:title[^Draft of \'.*]]">
<style type="text/css">
.exheading [type="checkbox"]{display:none;}
</style>
<div class="exheading" style="position:relative;">
<$checkbox field=<<stfield>> checked="yes" unchecked="no">
<h$hedr$ style="border-radius:4px; text-decoration:none; border:0px; margin-top:6px; margin-bottom:4px; padding-left:6px; padding-top:6px; padding-bottom:2px; background-color:$clr$;">
{{$:/core/images/unfold-button}}
<$transclude field="title" mode="inline"/><span style="position: absolute; right: 10px; font-size:smaller;"><$link>[edit]</$link></span>
</h$hedr$>
</$checkbox>
</div>
<div style="border-left: $lefbrdr$px solid $clr$; margin-left:15px; padding-left:10px; margin-right:15px;">
<$reveal stateTitle=<<currentTiddler>> stateField=<<stfield>>  type="match" text="yes">
<$transclude field="text" mode="block"/>
</$reveal>
</div>
</$list>
</$let>
\end

<<xpd-list tagged:"help" clr:"#3A3A3A">>

Now that I got the macro worked out, it’s time to make it a procedure. haha

I got hung up on stateTitle vs stateField. “Title” is not the title of the field, but the title of the tiddler that has the field. Field is not the value of the field, but the name/title of the field that has the value. badoink

And of course, <<currentTiddler>> gets more confusing when dealing with the list widget.

I’m still stumped as to why let must be used instead of set.