Requesting macro massage, willing to donate $50 to TW

You already wrote most of it (!?) - so is this sufficient? I’ve indented it for clarity but you can remove the indentation if you don’t like it.

\define block(span:"" tid:"") 
<$list filter='[[$tid$]is[tiddler]]'>
	<span class='$span$'>
		<details>
			<summary>
				<$view tiddler='$tid$' field='title'/>&nbsp;<$link>*</$link>
			</summary>
			<span class='indent1'>
				<$transclude tiddler='$tid$' field='text' mode='block'/>
			</span>
		</details>
	</span>
</$list>
<$list filter='[[$tid$]!is[tiddler]]'>
	<span class='$span$'>
		<span class='missing'>
			<$link to='$tid$'/>
		</span>
	</span>
</$list>
\end

…or, wait, you’re not asking for the various classes to be written, are you?

2 Likes

Here is a variant that uses a single list widget:

\define block(span:"" tid:"")
\define missing() <span class=<<__span__>> ><span class="missing"><$link to=<<__tid__>>/></span></span>
<$list filter="[<__tid__>is[tiddler]]" variable="ignore" emptyMessage=<<missing>> >
<span class=<<__span__>> ><details><summary><$view tiddler=<<__tid__>> field="title"/>&nbsp;<$link>*</$link></summary><span class="indent1"><$transclude tiddler=<<__tid__>> field="text" mode="block"/></span></details></span>
</$list>
\end
2 Likes

Good idea. If @DaveGifford prefers your method, I’m totally fine with it.

Thanks, @twMat and @saqimtiaz ! Both work equally great. And both ways are learning opportunities for me.

I have to step out for a bit, but I will make that donation today.

3 Likes

I prefer your indenting but doing the same in the single list widget version neatly requires TW 5.2.5 for nested multi-line macros:

\define block(span:"" tid:"")
\define missing()
	<span class=<<__span__>>>
		<span class="missing">
			<$link to=<<__tid__>>/>
		</span>
	</span>
\end missing
<$list filter="[<__tid__>is[tiddler]]" variable="ignore" emptyMessage=<<missing>> >
	<span class=<<__span__>>>
		<details>
			<summary>
				<$view tiddler=<<__tid__>> field="title"/>&nbsp;<$link>*</$link>
			</summary>
			<span class="indent1">
				<$transclude tiddler=<<__tid__>> field="text" mode="block"/>
			</span>
		</details>
	</span>
</$list>
\end block

or in 5.2.6 pre-release where you can indent pragmas:


\define block(span:"" tid:"")
	\define missing()
		<span class=<<__span__>>>
			<span class="missing">
				<$link to=<<__tid__>>/>
			</span>
		</span>
	\end missing
	<$list filter="[<__tid__>is[tiddler]]" variable="ignore" emptyMessage=<<missing>> >
		<span class=<<__span__>>>
			<details>
				<summary>
					<$view tiddler=<<__tid__>> field="title"/>&nbsp;<$link>*</$link>
				</summary>
				<span class="indent1">
					<$transclude tiddler=<<__tid__>> field="text" mode="block"/>
				</span>
			</details>
		</span>
	</$list>
\end block
1 Like

Cool stuff. Just one little nit-pick, which I also had to correct in my code: Probably best to use single ticks to wrap the filters.

WOW
I love the nested macros!
I love both solutions!
These solutions are like short lessons! One always learns reading these codes!

:heart_eyes:

Thank you @DaveGifford for your donation and creating excitement by raising questions.

Not really, there is no text substitution so no risk of anything breaking. However consistency between single and double quotes would be good.

What, really? I thought it is needed to handle This "dubious" tiddler title - no? Of course (I think), single quotes have the same problem but they’re much more uncommon than double quotes.

When you use variables instead of textual substitution, there is no such problem.

1 Like

Well, okay I haven’t left the house yet. Here is Mat’s version, with a tweak or two.

https://giffmex.org/experiments/block.macro.test.html#%24%3A%2F.giffmex%2Fmacro%2Fblock%2Ffor.editing:%24%3A%2F.giffmex%2Fmacro%2Fblock%2Ffor.editing%20[[Test%20outline]]%20%24%3A%2F.giffmex%2F.Stylesheet%2Findentlevels

I am noticing that in this set up, captions don’t work. Not sure what to do so that “caption if caption, title if no caption”

1 Like

It’s not clear exactly where you mean but this is if you want it as a link. If you don’t want it as a link, just remove the outer link tags.

<$link><$transclude field="caption"><$view field=title/></$transclude></$link>
1 Like

By the way, I updated my original code to consistently use single quotes in all places rather than single in some and double in some. It makes no difference on the outcome it is just for consistency/aesthetics.

It doesn’t mention in the docs for nested macro definitions that the end remains unnecessary for the inner macro if it’s only a one-liner. Maybe someone should add this! I never dared to try… :sweat_smile:

Anyway, good to know.

The single line nested macros were supported before TW5.2.5 like other local pragmas!
It is 5.2.5 where multi line nested macros were introduced!

BTW, I totally agree with you to add this to documentation!

1 Like

@Yaisog @Mohammad could one of you be so kind as to create a documentation update PR?

1 Like

Sure
I create the PR.

1 Like

Done: Update Macro Definitions in WikiText.tid by kookma · Pull Request #7201 · Jermolene/TiddlyWiki5 (github.com)

3 Likes

Thanks twMat, it worked great!