How can I Create virtual tiddler adding a prefix/suffix from a template

I’ll edit the overlong question when I’m more sure of what I’m asking!

OK, I’m sure this is easy, and I SHOULD be able to work it out but…

I would like for a some text which is generated from a view template in an existing tiddler to become a link which will open a new tiddler with the current tiddlers name prefixed with a word. (In this case the word is Questions).

This is the view template: (from @Mohammad :slight_smile: )

\function topic.filter() [tag[Question]contains:topic<currentTiddler>]
<$list filter=[{!!title}tag[Topic]]>
<div class="kk-pdeck-topic-stat">
<span>Statistics</span>
<span>Exams: <$count filter="[topic.filter[]get[exam]enlist-input[]unique[]]"/></span>
<span>Questions: <$count filter="[topic.filter[]]"/></span>

The word Questions there is what I would like to create a new tiddler, possibly temporary, on clicking on.

I would then like the following displayed in this new tiddler (again, thanks @Mohammad )

</div>
<$list filter="[tag[Question]contains:topic<currentTiddler>]">
<$link/><br/>
<div class="kk-pdeck-examlist"><$list filter="[enlist{!!exam}]" join=" | "><$text text=<<currentTiddler>>/></$list></div>
<$list>
</$list>

but of course current tiddler there will be the topic tiddler without the Questions prefix…

This is an all an attempt to hack @Mohammad 's Problem Deck Plugin

So for example Force has some questions, the first bit of code displays this at the top of the tiddler.
image

Clicking on questions takes us to Questions: Force or Force Questions and then lists the questions.
image

1 Like

checks to see if he smells :poop: … Anyone?

Ok, I’m going to give it a try, even though I’m not sure I understand clearly what you want…

So, first to build new tiddler title add this code at the beginning of the viewtemplate:

\define newquestionprefix() $:/temp/Question
\function get.newquestiontitle() [<currentTiddler>] [<newquestionprefix>] +[join[ ]]

Then, the template for new tiddlers:

  • create a tiddler, name it inside system namespace to prevent it being listed with every other Question tagged tiddler, say $:/ste_w/question-template, and tag it Question
  • in its text field paste the code you want to see in every tiddler (we’ll change it later)

Next, how to create new tiddlers:

  • add a procedure at the beginning of the viewtemplate:
\procedure newquestionactions()
<$action-createtiddler $basetitle=<<get.newquestiontitle>> $template="$:/ste_w/question-template" topic=<<currentTiddler>>/>
\end
  • surround “Questions:” label with a button:
<span><$button class="tc-btn-invisible" actions="""<<newquestionactions>>""">Questions:</$button> <$count filter="[topic.filter[]]"/></span>

This should already create a new tiddler when you click on “Questions”.

Finally, fix new tiddler content to remove prefix: this one should be easy because “parent” question tiddler title is already stored in current tiddler’s “topic” field

</div>
<$list filter="[tag[Question]contains:topic{!!topic}}]">
<$link/><br/>
<div class="kk-pdeck-examlist"><$list filter="[enlist{!!exam}]" join=" | "><$text text=<<currentTiddler>>/></$list></div>
<$list>
</$list>

BUT! Here I can’t understand what you want to do: why does the new tiddler text display a div which contains it’s own text which contains a div which contains its own text and so on…?

Anyway, I hope this will get you started.

Fred

Cheers. I’ll have a look at this after the weekend.

As as start I was hoping to reuse some code from the problem deck TW linked in the first post.

Keep using the existing templates. The code above is taken from the questions style sheet.

I have, I think, followed your instructions…

Tagged $:/tags/ViewTemplate I have a tiddler containing:

\procedure newquestionactions()
<$action-createtiddler $basetitle=<<get.newquestiontitle>> $template="New Tiddler 12" topic=<<currentTiddler>>/>
\end

\define newquestionprefix() $:/temp/Question
\function get.newquestiontitle() [<currentTiddler>] [<newquestionprefix>] +[join[ ]]

and a separate tiddler also tagged $:/tags/ViewTemplate

Containing


\function topic.filter() [tag[Question]contains:topic<currentTiddler>]


<$list filter=[{!!title}tag[Topic]]>
	<aside class="kk-pdeck-topic-stat">
		<span>Statistics</span>
		<span>Exams: <$count filter="[topic.filter[]get[exam]enlist-input[]unique[]]"/></span>
		<span><$button class="tc-btn-invisible" actions="""<<newquestionactions>>""">Questions:</$button> <$count filter="[topic.filter[]]"/></span>

	</aside>

This generates a tiddler with a $:/temp/Question suffix and the code \function topic.filter()…code above.

Adding the final bit

<$list filter="[tag[Question]contains:topic{!!topic}}]">
<$link/><br/>
<div class="kk-pdeck-examlist"><$list filter="[enlist{!!exam}]" join=" | "><$text text=<<currentTiddler>>/></$list></div>
<$list>
</$list>

generates a [Filter error: Missing [ in filter expression]

error

I didn’t test your whole code, but there’s a filter syntax error on the first line of “the final bit”:
<$list filter="[tag[Question]contains:topic{!!topic}}]">
should be instead:
<$list filter="[tag[Question]contains:topic{!!topic}]">

Fred

@tw-FRed thank you, I’d have stared at the for hours and not spotted it.

OK, almost there.

Clicking on the Question button in the topic tiddler creates a new Tiddler that looks like this:

So it’s copying the template code from the template tiddler and showing the incorrect title. It is also creating the tiddler silently, it appears in the recent list, but not in the story river.

@Mohammad I kind of feel I should be able to slot this into your Simple method…
Is this behaviour because I’m clashing with things already in the P Desk? (I’ve removed the $:/plugins/kookma/pdeck/viewtemplates/topic tiddler)

@tw-FRed thanks for your help here.

Current Code Below:

Two tiddlers, both tagged $:/tags/ViewTemplate

\define newquestionprefix() $:/temp/Question
\function get.newquestiontitle() [<currentTiddler>] [<newquestionprefix>] +[join[ ]]

\procedure newquestionactions()
<$action-createtiddler $basetitle=<<get.newquestiontitle>> $template="$:/New Tiddler 13" topic=<<currentTiddler>>/>
\end

\function topic.filter() [tag[Question]contains:topic<currentTiddler>]
<$list filter=[{!!title}tag[Topic]]>
	<aside class="kk-pdeck-topic-stat">
		<span>Statistics</span>
		<span>Exams: <$count filter="[topic.filter[]get[exam]enlist-input[]unique[]]"/></span>
		<span><$button class="tc-btn-invisible" actions="""<<newquestionactions>>""">Questions:</$button> <$count filter="[topic.filter[]]"/></span>
	</aside>

and

<$list filter="[tag[Question]contains:topic{!!topic}]">
<$link/><br/>
<div class="kk-pdeck-examlist">
			<$list filter="[enlist{!!exam}]" join=" | "><$text text=<<currentTiddler>>/></$list>
		</div>
	<$list>
</$list>

Well… it’s using the title you told it to use! Here’s the function in question:

\function get.newquestiontitle() [<currentTiddler>] [<newquestionprefix>] +[join[ ]]

Whereas I suspect you may actually want something more like this:

\function get.newquestiontitle() [<newquestionprefix>] [<currentTiddler>] +[join[/]]

Note that join joins all its inputs in the order they’re presented, inserting its parameter at each join site.

This is normal behavior for $action-createtiddler (cf. the tm-new-tiddler message, which creates a new draft and opens it in the story river). To automatically open a tiddler created by $action-createtiddler, you need to pair it with $action-navigate, like so:

\procedure newquestionactions()
<$action-createtiddler
	$basetitle=<<get.newquestiontitle>>
	$template="$:/New Tiddler 13"
	topic=<<currentTiddler>>
>
	<$action-navigate $to=<<createTiddler-title>>/>
</$action-createtiddler>
\end

Here, I’m using the <<createTiddler-title>> variable, which is defined only within the content of the $action-createtiddler widget to refer to the title of the newly created tiddler (which may or may not match the $basetitle value, depending on whether numbers have to be appended to get a unique title). This means we also have to use the long form of the widget, with an explicit closing tag </$action-createtiddler>.

For future reference, the last example in the $action-createtiddler docs also illustrates this technique. :slight_smile:

3 Likes

I haven’t tried to follow everything here…

But this may be a case where you don’t even need to create a tiddler — just use a virtual tiddler template, and a formulaic link in any tiddler XYZ to a “missing” tiddler with a name like “Questions about XYZ”…

If “Questions about XYZ” is in story river (even if it doesn’t exist), a view template (which applies only to tiddlers with titles that start with “Questions about” and end with the name of a tiddler that does exist) can display … [template worth of stuff based on XYZ].

1 Like

OK, @Ste_W — here’s a live example from my writing-coach site:

https://writing-coach.tiddlyhost.com/#dangling%20participle

Lots of writing-correction notes have examples. I had initially designed the site so that examples of problem-sentences, with corrections, appear at the bottom (with a view Template). BUT I could also create a button that opens a “quiz”, in a new tiddler, for the issue in question. EDIT: OK, I could… and I did!

With the link above, you’ll find at bottom of relevant tiddlers, a button for “Quiz on examples for dangling participle” (or similar).

A view template that appears only for tiddlers with that title pattern then appears in the story river, based on a list of tiddlers that provide examples of that error — with each example of error-pattern-sentence shown at left, and corrected sentence appearing at right on hover, with further drop-down (below the whole list of examples) for explanatory details.

I haven’t created an actual tiddler for this quiz (temporary or otherwise)! But the story river “hallucinates” a complex tiddler there, because of the view template that kicks in.

EDIT: heck, let’s even link to the virtual tiddler with the examples quiz for dangling participles

The fact that you can link directly to it should show one advantage of this approach (compared a button for creating a temporary tiddler). You can send your audience straight to the Questions / Quiz template with a permalink, no need for them to click a button first.

EDIT to add: preview of what the virtual tiddler currently looks like:

2 Likes

Hello!

Yes, virtual on the fly tiddler!

I’m on chrome on my desktop and pressing the quiz button at the bottom of your first link doesn’t seem to do anything.

Your link to the virtual tiddler does not seem to show anything, but yes that kind of thing would be perfect!

@etardiff I’ll have a closer look at your help shortly when the busyness at work has calmed down!

OOPS!

My solution was set up to show “missing” (virtual) tiddlers only to me (the author), not to web visitors…

(This is a setup copied over from another of my hosted wikis, where “virtual” tiddlers are just for my own authoring/utility purposes. For anyone curious about this, the TiddlyTweaks read-Only solution has a control-panel area for css to show when not in authenticated authoring mode, and I just had this line of read-only css: .tc-tiddler-missing { display: none; })

Sorry about that @Ste_W — I’ve fixed that problem now… want to try again? Here’s the link again

1 Like

Much appreciated. I’ll have a lookup and a poke on Monday.

Oh, that’s a great idea! I have several potential uses for that, although I haven’t used TiddlyTweaks read-Only before.

(I also had wondered why it wasn’t working for me, but hadn’t found the time to investigate before reporting.)

But I mostly am responding to say that I love the term shrug party. Is that original?

¯\_(ツ)_/¯

Since it’s not very nice to mention a solution without linking to it, here’s a link to the demo page for TiddlyTweaks readonly solution:

https://read-only.tiddlyhost.com/

I really love how it bundles together a few different mini-tools that might have a role in shifting how a site should present to non-author viewers.

I also have a class “author-note” (applied to anything from an individual span or div to a tiddler or a view template) that doesn’t display at all for non-author viewers, and which displays with a distinct background and border for me, so that I’m more confident about which parts are for my eyes only. (Of course, disclaimer applies — this isn’t genuine privacy or security, just more like “back room” elements of the interface that would be confusing or distracting from the public-facing functions of the wiki.)

Yes, “shrug party” is one of my (as far as I know) original diagnostic terms. It’s at the other end of the spectrum from the “piñata party” problem. :wink:

2 Likes

I think you are much cleverer than I at this TW business.
I have stolen your code from $:/examples to make the button.

<$button>
<$action-navigate $to={{{ [<currentTiddler>addprefix[examples for ]] }}} $scroll="yes"/>
Quiz on <$text text={{{ [<storyTiddler>addprefix[examples for ]] }}}/>
</$button>

But I’m unsure what the next button does:

@@float:right; 
$:/examples <$button> Make example for this diagnosis
<$action-createtiddler $basetitle="$:/example" tags="$:/example">
	<$action-navigate $to=<<createTiddler-title>>/>
</$action-createtiddler>
</$button>
@@

So I kind of mashed them together to get

\function topic.filter() [tag[Question]contains:topic<currentTiddler>]
<$list filter=[{!!title}tag[Topic]]>
	<aside class="kk-pdeck-topic-stat">
		<span>Statistics</span>
		<span>Exams: <$count filter="[topic.filter[]get[exam]enlist-input[]unique[]]"/></span>
		<span>
            <$button>
                  <$action-createtiddler $basetitle={{{ [<currentTiddler>addprefix[Questions for ]] }}}>
                  </$action-createtiddler>  
                  <$action-navigate $to={{{ [<currentTiddler>addprefix[Questions for ]] }}} $scroll="yes"/>
Questions:
</$button>

Which creates a correctly titled tiddler.

I’m having difficulty getting content into it however.

Trying to adapt your $:/template/quiz-for-xyz-template tiddler.

<% if [<storyTiddler>prefix[Questions for]] %>

<$let parentTiddler={{{ [<storyTiddler>removeprefix[Questions for ]join[ ]] }}}>

<$list filter="[<parentTiddler>tag[Question]]">
	<table class="table-borderless kk-pdeck-question-info">
		<$list filter=[question.fields[]] variable=field><<showField>></$list>
  </table>
</$list>

It looks like you’re creating a tiddler with a title like “Questions for …” and that’s different from my solution’s approach.

What I’m suggesting (and what I did with the “quiz for…” theme) is not to create an actual tiddler to hold each quiz, but to use a view template that works even at a “missing tiddler node” to pull together a quiz interface. There needs to be a button to put that “node” into the story list, precisely because there’s no such tiddler.

Then the view-template for the “quiz/questions for this theme” can use a filter to pull on the relevant system-tiddlers for the theme. (In my case, the filter focuses on a “parent” field in those system tiddlers.)

(I have a to-do refactoring on my horizon, since really it makes sense not to spell out the title of the parent-theme tiddler, but to reference the code field in a parent-code list-type field. My code field for each theme is not only unique but short (no space!) and will play more nicely with list-type fields. That way a single example can be more smoothly tapped by multiple quiz-theme sets.)

Separately (for my convenience) I also set up a button (which displays within the “theme/issue” tiddler) to create “quiz line-items” for that theme. Those are real tiddlers! But I could just as easily make those manually, without a button. Those items live in system name-space, with the $:/examples tag.

I think your confusion comes from the fact that I have two buttons:

  • One of them is optional — just a convenience to generate example-tiddlers (real tiddlers, with system prefix $:/ex) to hold example questions. Some field or other simple parameter needs to help track the relational connection between this example and the parent theme(s).
  • The other button “navigates to” a quiz node — which is a virtual tiddler with a formulaic (non-system) name. The solution relies on a view template that serve up a thematic quiz, based on the name of the node, and appropriate filter conditions to pull on the example tiddlers. That second button (and the view template!) is essential to my solution.

Rather than try to troubleshoot your code (which would take more attention than I can devote at the moment), I did comment my quiz template, hoping it can serve as a walk-through.

1 Like

That’s helped!

Final question:

I create the virtual tiddler with this

<$button>
 <$action-navigate $to={{{ [<currentTiddler>addprefix[Questions for ]] }}} $scroll="yes"/>
Questions:
</$button>

which creates a temp tiddler but claims Missing tiddler “Questions for SUVAT” – click to create

I have the correct information displayed in my tiddler with the following (heavily stolen from your stuff)

<% if [<storyTiddler>prefix[Questions for ]] %>

<$let parentTiddler={{{ [<storyTiddler>removeprefix[Questions for ]join[ ]] }}}>

<$list filter="[tag[Question]contains:topic<parentTiddler>]"><$link/><br/>

<div class="kk-pdeck-examlist">
			<$list filter="[enlist{!!exam}]" join=" | "><$text text=<<currentTiddler>>/></$list>
		</div>

So the final bit of the puzzle, how do I wrap it up so that it’s not a missing tiddler?

Shucks, the idea of “missing tiddler” is so misleading!

The crux of this approach is that you don’t ever take a step to make this virtual tiddler (as it displays in the story river) “not a missing tiddler”. Rather, you just make sure that your viewtemplate tiddler displays in the story river for certain node titles (otherwise known as a tiddler title), so that it no longer matters that the tiddler for this node is “missing” (in terms of there being nothing there with that title in the json array).

But perhaps you mean: How to get rid of the missing tiddler messageMissing tiddler "<$text text=<<currentTiddler>>/>" -- click {{||$:/core/ui/Buttons/edit}} to create? If you are seeing your template, but below the missing tiddler message, then that’s easy to solve!

There are at least three options for bypassing that message.

  • Simply edit shadow tiddler $:/language/MissingTiddler/Hint to delete that message altogether, OR replace it with something like a dynamic table of tiddlers with filter [tag<currentTiddler>] (perhaps adding other field-based connections, etc., as with author field connections in a biblio wiki). Of course, this change will affect the whole wiki. I tend to do this, since I do so much with missing tiddlers, and I don’t need the reminder how to create a real tiddler with that title.
  • Edit shadow tiddler $:/core/ui/ViewTemplate/body/default (which transcludes the missing tiddler message if there’s no “body” section to transclude), so as to bypass that “missing tiddler” message (under certain conditions, perhaps — so this is easy if you really want to keep that message showing up for ordinary missing tiddlers).
  • Most sophisticated and powerful (and without editing a shadow): Add a cascade condition (in your Control Panel Advanced Cascades tab) for the View Template Body (tagged $:/tags/ViewTemplateBodyFilter). Order it prior to the default template (add list-before field with $:/config/ViewTemplateBodyFilters/default, and have it catch the relevant tiddlers and direct them appropriately (as in [prefix[Questions for ]then[MyQuizTemplate]] — where MyQuizTemplate specifies the view template you’ve just created). If you choose this option, you can take the view template tag off of MyQuizTemplate, and remove the conditional-syntax framing.

Please let me know if your question is different from what I tried to address!

2 Likes