How can I Create temp tiddler on the fly 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