I want to substitute a ViewTemplate with a fields value to transclude into html-details

I aim to create html-details for all tiddlers from the filter foo and link to each tiddler in the summary but omitt the suffix bar.
That doesn’t work if the tiddler uses a ViewTemplate.

The short version: I think I am lost in ticks and brackets once again and the last part of my procedure is to substitute the transclusion with a concatenation of a fields value with fixed text. someting like

.
{{{ ||`$:/_/TiddlerTyp/${[{!!TiddlerTyp}]}/$ViewTemplate` }}}
.

otherwise it works.

The working code is:

\procedure filterdetails(input-filter:"[tag<currentTiddler>nsort[title]]", cut-input)
	<$list filter=<<input-filter>> >
		<details><summary><$link to=<<currentTiddler>>><$text text={{{ [<currentTiddler>trim:suffix<cut-input>] }}}/></$link></summary><div>
			{{||$:/_/TiddlerTyp/book/ViewTemplate}}
		</div></details>
	</$list>
\end

I have set it up and the longer description at.

Sidenote @kooma: while writing this I noticed, that the numbers of the footnotes from Refnotes are scrambled. I didn’t research yet weather this is to be expected.

Your backtick syntax looks correct, you just can’t use non-literal values with short-form transclusions. (The clue is in the proper name, substituted attribute values — i.e., this syntax only works when setting the value of an attribute in a widget or HTML element.) Try using the $transclude widget instead:

<$transclude $tiddler=`$:/_/TiddlerTyp/${ [{!!TiddlerTyp}] }$/ViewTemplate` $mode=block />

This should replace {{||$:/_/TiddlerTyp/book/ViewTemplate}} in your hard-coded working version.

Edit: Forgot to explain one crucial but non-intuitive detail: in the $transclude widget, $tiddler (modern syntax) or tiddler (legacy syntax) refers to the tiddler being used as the template, not the tiddler whose field content is being used — which is always <<currentTiddler>>. Thus, you could rewrite {{||$:/_/TiddlerTyp/book/ViewTemplate}} like this:

<$transclude $tiddler="$:/_/TiddlerTyp/book/ViewTemplate" />

or {{Book||$:/_/TiddlerTyp/book/ViewTemplate}} like this:

<$tiddler tiddler="Book">
<$transclude $tiddler="$:/_/TiddlerTyp/book/ViewTemplate" />
</$tiddler>
2 Likes

That breaks it.
I need to transclude the currentTiddler but through a Viewtemplate, that I have to pass in the call somehow.

Am I misunderstanding your goal? Here’s the code I just tested in your wiki, replacing the link I mentioned in your code:

\procedure filterdetails(input-filter:"[tag<currentTiddler>nsort[title]]", cut-input)
	<$list filter=<<input-filter>> >
		<details><summary><$link to=<<currentTiddler>>><$text text={{{ [<currentTiddler>trim:suffix<cut-input>] }}}/></$link></summary><div>
			<$transclude $tiddler=`$:/_/TiddlerTyp/${ [{!!TiddlerTyp}] }$/ViewTemplate` $mode=block />
		</div></details>
	</$list>
\end

<<filterdetails "[[Alice in Wonderland]] [[Peter and Wendy]]">>

Here’s the output:

I did also edit my previous post to clarify the use of $tiddler in $transclude, which is used to specify the transclusion template.

First: Thanks!

Your solution works for tiddlers with the TiddlerTyp=book.
But I have others like TiddlerType=person and most tiddlers use the standard ViewTemplate so they don’t need a TiddlerTyp at all ( eg. books in details )

I want to just call it like <<filterdetails>> in tiddlers of any TiddlerTyp, thus I want to pass it from a field. other wise I would just hard-code it.

1 Like

“book” is not hardcoded anywhere, so I would expect my previous code to work with any tiddler with the TiddlerTyp field. You don’t seem to have any other TiddlerTyp values in your demo, though, so I can’t test it.

However…

Ah, I was assuming you were using the field more commonly than you are. In that case, I’d try this alternative:

\procedure filterdetails(input-filter:"[tag<currentTiddler>nsort[title]]", cut-input)
	<$list filter=<<input-filter>> >
		<details><summary><$link to=<<currentTiddler>>><$text text={{{ [<currentTiddler>trim:suffix<cut-input>] }}}/></$link></summary><div>
			<$transclude $tiddler={{{ [{!!title}get[TiddlerTyp]addprefix[$:/_/TiddlerTyp/]addsuffix[/ViewTemplate]] ~[{!!title}] }}} $mode=block />
		</div></details>
	</$list>
\end

This will construct an appropriate ViewTemplate title if and only if the TiddlerTyp is non-blank. Otherwise, it will use the tiddler as its own template, so it should appear as (the tiddler body) would if you opened it in the story river.

2 Likes

You can give this a try for the filterdetails procedure:

\procedure filterdetails(input-filter:"[tag<currentTiddler>nsort[title]]", cut-input)
<$list filter=<<input-filter>> >
    <details>
        <summary><$link to=<<currentTiddler>>><$text text={{{ [<currentTiddler>trim:suffix<cut-input>] }}}/></$link></summary>
        <div>
        <% if [<currentTiddler>has[TiddlerTyp]] %>
            <$tiddler tiddler=<<currentTiddler>>>
			    <$transclude tiddler={{{ [[$:/_/TiddlerTyp/]] [<currentTiddler>get[TiddlerTyp]] [[/ViewTemplate]] :and[join[]] }}} mode="block"/>
            </$tiddler>
        <% else %>
		    <$transclude />
        <% endif %>
        </div>
    </details>
</$list>
\end
1 Like

Many Thanks to @etardiff and @Brian_Radspinner! Both variants work.

I needed to add block mode in the else-transclusion otherwise tables and other WikiText do not render in the html-details.

\procedure filterdetails(input-filter:"[tag<currentTiddler>nsort[title]]", cut-input)
<$list filter=<<input-filter>> >
    <details>
        <summary><$link to=<<currentTiddler>>><$text text={{{ [<currentTiddler>trim:suffix<cut-input>] }}}/></$link></summary>
        <div>
        <% if [<currentTiddler>has[TiddlerTyp]] %>
            <$tiddler tiddler=<<currentTiddler>>>
			    <$transclude tiddler={{{ [[$:/_/TiddlerTyp/]] [<currentTiddler>get[TiddlerTyp]] [[/ViewTemplate]] :and[join[]] }}} mode="block"/>
            </$tiddler>
        <% else %>
		    <$transclude mode="block"/>
        <% endif %>
        </div>
    </details>
</$list>
\end

Special thanks for that explanation. I had read this somewhere. Hopefully I understood it this time reading it twice.