Adding emptyMessage to things that don't have it?

Just a quick question, what would be the objectively best way to add an empty message to a tiddler?

ie, lets say you are using the vanilla toc macro that is baked into the core, and would like to add the option to just, click a button to create a new tiddler tagged with whatever the tag the toc is looking for if there isn’t any tiddlers in the toc already.

What I came up with is:

<div class="tc-table-of-contents">
<<toc-selective-expandable tag:"Contents">>
</div>

<$reveal type="match" state={{{ [tag[Contents]] }}} text="">
"""
Click {{Contents||$:/core/ui/Buttons/new-here}} to create a new tiddler here.
"""
</$reveal>

I’m just wondering if there would be a way to slim what I threw together, or make it more modular so it can be reused in other usecases, because only a handful of macros do support the emptyMessage… parameter? (sorry, coming back to TW after a small hiatus, my lingo is a bit rusty, so I may refer to things incorrectly.)

Maybe I’m just tired but I don’t understand your question. What does “add an empty message to a tiddler” mean? Is it perhaps the message showing in missing tiddlers? But you mention the emptyMessage param which is something else. Your question seems to mix in several things.

Here’s another way:

<$list filter="[tag[Contents]count[]match[0]]">
Click {{Contents||$:/core/ui/Buttons/new-here}} to create a new tiddler here.
</$list>

-e

1 Like

To be fair, I didn’t really ask the question well haha

I think the goal is creating a quick and reusable way of adding the same sort of functionality like the emptyMessage param provides when you use it in something like a list widget, where if there isn’t any text, it will show an empty message as placeholder text, either as it’s own macro, or a text snippet, etc.

I’m not sure how much that helps in terms of what I am trying to ask, because in all honesty even I am not 100% sure that is the right way to ask it.

I’m more or less asking for how others would approach the situation of wanting to add that to something they were working on, but wanted to keep it simple and reusable for other uses later on.

Oh, that’s a nice way to do it. I think the way I showed above doesn’t actually work, so this is much better lol

Actually the empty Message means the filter returns no titles at all, not even titles of non existent or missing tiddlers.

Perhaps what is wanted here is empty tiddlers, tiddlers with out a text field, even missing, as is common for tags.

They may have a title and other fields but the text field is blank.

So you want “placeholder text” to appear when a tiddler has no text… Here’s how to do this:

Start by creating a separate tiddler (e.g., “EmptyTiddlerTemplate”) containing the following:

<$list filter="[{!!text}is[blank]]" variable=none>{{||EmptyTiddlerPlaceholder}}</$list>

Tag this tiddler with $:/tags/ViewTemplate. This will automatically show the above content at the bottom of every tiddler and checks to see if the text field of the current tiddler is blank. If it is, it does a “template transclusion” to show the “EmptyTiddlerPlaceholder” content.

Next, create the “EmptyTiddlerPlaceholder” tiddler, containing whatever you want to appear when a tiddler has no text. Perhaps something like this:

<$list filter="[tag<currentTiddler>count[]match[0]]" variable=none>
Click {{||$:/core/ui/Buttons/new-here}} to create a new tiddler here.
</$list>

Note how the $list widgets are using variable=none. This ensures that the value of the currentTiddler variable remains unchanged, so that the {{||EmptyTiddlerPlaceholder}} and {{||$:/core/ui/Buttons/new-here}} template transclusions will be able to use the name of the current tiddler when they are processed.

Also note that the “EmptyTiddlerTemplate” and “EmptyTiddlerPlaceholder” tiddlers could be combined into a single tiddler, like this:

<$list filter="[{!!text}is[blank]]" variable=none>
<$list filter="[tag<currentTiddler>count[]match[0]]" variable=none>
Click {{||$:/core/ui/Buttons/new-here}} to create a new tiddler here.
</$list>
</$list>

However, by splitting them into two tiddlers, it makes it easier to use more complex “EmptyTiddlerPlaceholder” content, without inadvertently affecting the ViewTemplate infrastructure “glue”.

enjoy,
-e

Alrighty, after a full nights rest and a little bit of time to give it some thought, I think I have a better idea of what I had originally wanted to ask.

What I was looking for was a widget or macro that can be placed along with other widgets / macros, that can either piggyback off what they are looking for, ie using a list widget to filter for tiddlers that are tagged woth Contents, or be given the same paramaters to look for, and if there are none, the additional widget using the same filter allows you to add in an emptyMessage if there aren’t any results of the filter.

Unfortunately filtering for a blank text would not work because of the inclusion of the widgets inside, unless you used regex to filter for things prefixed with << or <$

The intent is adding an emptyMessage to widgets that do not have it without having to modify the widget itself, like giving it an addon almost, and what brought this thought to me in the first place was wanting to add placeholder text to a toc if no tiddlers were tagged with what it was filtering for.

I should mention that the usage of wikitext such as wikilinks or transclusion of text from another tiddler would be wanted, where you can customize each use to have either the same default text or custom placeholder text.

For instance, if I had a toc that is looking for the tag Contents you could do something like

<div class="tc-table-of-contents">
<<toc-selective-expandable tag:"Contents">>
</div>

<<emptymessage filter:"[tag[Contents]count[]match[0]]"
text:"""
{{A tiddler with some text}}, a {{Contents||button to add a tiddler tagged fo fill the filter}}, etc.
""">>

ErikShulman’s alternative to what I proposed was able to achieve that for the toc aspect, however I don’t know for how many other uses it could be used for. Considering its just a filter for a tag, probably most widgets.

I’m just trying to think of where that wouldn’t be enough :thinking: because J do want to find the most modular way to do this, rhe way that works best with the other widgets both in the core and potentiall with plugins.