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:

2 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:

1 Like