It's ALMOST working. If/ Else

It almost works…Hopefully I’m just missing a bracket…

IF a tiddler has the prefix Questions for then remove the prefix. IF a tiddler tagged Question has a field called topic and in that field is the name of Questions for Something THEN write some text in the virtual tiddler Questions for Something and list the Question Tiddlers which are named in the topic field and match Questions for Something.

ELSE do it again but IF a tiddler tagged Question has a field called relevant and put some different text in there.

THEN do the div class bit at the end.

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

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

<%if  [<storyTiddler>tag[Question]contains:topic<parentTiddler>]] %>

Example exam  and assignment questions for <$tiddler tiddler=<<parentTiddler>> > <$link/> </$tiddler>

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

<%else%>

<%if  [<storyTiddler>tag[Question]contains:relavent<parentTiddler>]] %>

Exam question that use this:<$tiddler tiddler=<<parentTiddler>> > <$link/> </$tiddler>
<$list filter="[tag[Question]contains:relevant<parentTiddler>]"><$link/><br/>

<%endif%>


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

There seems to be a serious problem with your nesting.

It’s easiest to see by actually nesting your code manually. See the comments inline.

<%if [<storyTiddler>prefix[Questions for ]] %>
    <$let parentTiddler={{{ [<storyTiddler>removeprefix[Questions for ]join[ ]] }}}>
        <%if  [<storyTiddler>tag[Question]contains:topic<parentTiddler>]] %>
            Example exam  and assignment questions for <$tiddler tiddler=<<parentTiddler>> > <$link/> </$tiddler>
            <$list filter="[tag[Question]contains:topic<parentTiddler>]"><$link/><br/>
            <!-- `list` above never closed -->
        <%else%> 
            <!-- should the `else` above be combined with the `if` below as `<% elseif %>`?-->
            <%if  [<storyTiddler>tag[Question]contains:relavent<parentTiddler>]] %>
                Exam question that use this:<$tiddler tiddler=<<parentTiddler>> > <$link/> </$tiddler>
                <$list filter="[tag[Question]contains:relevant<parentTiddler>]"><$link/><br/>
                <!-- `list` above never closed -->
            <%endif%>
            <div class="kk-pdeck-examlist">
                <$list filter="[enlist{!!exam}]" join=" | "><$text text=<<currentTiddler>>/></$list>
            </div>
        <!-- if-else above never closed-->
    <!-- `let` above never closed-->
<!-- `if` above never closed-->

I see Eric is typing as well. If he doesn’t suggest an answer, I’ll see if I can figure out your requirements to do this right. But you might want to look at this indented structure to see if you can do it yourself with these hints.

(I know that you can ignore any set of final closing tags in a tiddler and TW will infer them, but I’d recommend not doing this until you are really comfortable with such nesting structures… if even then.)

1 Like
<$list filter="[<storyTiddler>removeprefix[Questions for ]]" variable="parentTiddler">
	<%if  [<storyTiddler>tag[Question]contains:topic<parentTiddler>] %>
		Example exam and assignment questions for
		<$link to=<<storyTiddler>>><$text text=<<parentTiddler>>/></$link><br/>
		<$list filter="[tag[Question]contains:topic<parentTiddler>]"><$link/><br/></$list>
	<%elseif [<storyTiddler>tag[Question]contains:relavent<parentTiddler>] %>
		Exam question that use this:
		<$link to=<<storyTiddler>>><$text text=<<parentTiddler>>/></$link><br/>
		<$list filter="[tag[Question]contains:relevant<parentTiddler>]"><$link/><br/></$list>
	<%endif%>
</$list>
<div class="kk-pdeck-examlist">
	<$list filter="[enlist{!!exam}]" join=" | "><$text text=<<currentTiddler>>/></$list>
</div>

Notes:

  • Use <$list ...> for first conditional so it can also extract the parentTiddler variable at the same time. Note there is only one item produced by this filter, so there is no need for join[ ] at the end.
  • Use <%if...%> topic list output here <%elseif ...%> relevant list output here <%endif%> to show either “topic” OR “relevant” list output. If you want to show BOTH, then replace the <%elseif ...%> with <%endif%><%if ...%>
  • Remove extra ] at the end of the %if and %elseif filters.
  • $link to the storyTiddler while displaying the shorter parentTiddler text.
  • The inner <$list ...> widgets need matching </$list> to end them.

Let me know how it goes…

enjoy,
-e

4 Likes

Thank you both. I’ll have a stab at it tomorrow.

So I thought I’d try stripping it back a bit:

<%if [<storyTiddler>prefix[Questions for ]] %>
    <$let parentTiddler={{{ [<storyTiddler>removeprefix[Questions for ]] }}}><$let/>
           
        <%if  [<storyTiddler>tag[Question]contains:topic<parentTiddler>]] %>
           Some text 
        <%elseif [<storyTiddler>tag[Question]contains:relevant<parentTiddler %>
            Something else
<%endif%>

But both a topic and a relevant both return Some Text not a Some text and a Something else respectively.

Adding the double square brackets at the end of relevant seems to break it more.

I think this fixes it:

<%if [<storyTiddler>prefix[Questions for ]] %>
    <$let parentTiddler={{{ [<storyTiddler>removeprefix[Questions for ]] }}}><$let/>
        <%if  [<storyTiddler>tag[Question]contains:topic<parentTiddler>] %>
            Some text 
        <%elseif [<storyTiddler>tag[Question]contains:relevant<parentTiddler>] %>
            Something else
        <% endif %>
    </$let>
<% endif %>

The filters in both of your if/elseif clauses were broken. The first one had an extra closing bracket:

        <%if  [<storyTiddler>tag[Question]contains:topic<parentTiddler>]] %>
        <!--                                                     here --^   --->

And the second filter wasn’t closed at all:

        <%elseif [<storyTiddler>tag[Question]contains:relevant<parentTiddler %>
        <!--                                                         here --^   --->

I like to think of filters as a collection of operator/parameters pairs, such as

operator parameters
title1 <storyTiddler>
tag [Question]
contains:topic <parentTiddler>
contains:relevant <parentTiddler>

1 title can be skipped if it’s the first operator

Then these pairs are concatenated, and the whole thing is wrapped in a [ - ] pair. That is a full filter run.

There are additional complexities. We see contains:topic has some internal structure to it, and one operator can have multiple parameters, separated by commas. like [range[1],[12]]. But we can mostly ignore those to gain a basic understanding.

Operands have any of three types of brackets: [ - ] is for literal text, < - > is for variables in memory, and { - } is for tiddler contents. That last has full syntax of {tidname!!fieldname}, but you can skip tidname if it’s the current tiddler, and you can skip !!fieldname if the field is “text”.

One result of this syntax is that a filter run will always end with exactly two closing brackets, and the final one will be ]. Thus the only closings allowed are ]], >], and }]. There will also never be three consecutive brackets anywhere in a filter run.

2 Likes

We did completely remove the operand(s) keyword form the documentation and replaced it with parameter(s)

@Scott_Sauyet – Your table should be operator and parameters

Fixed in the original, thank you.

1 Like

As I previously noted, instead of using <%if ...> for the outer conditional, you can use an “old style” $list widget and combine the conditional test and the <$let parentTiddler=... assignment into a single widget action, like this:

<$list filter=[<storyTiddler>removeprefix[Questions for ]] variable="parentTiddler">
    <%if [<storyTiddler>tag[Question]contains:topic<parentTiddler>] %>
        Some text 
    <%elseif [<storyTiddler>tag[Question]contains:relevant<parentTiddler>] %>
        Something else
    <%endif%>
</$list>

This works because removeprefix[...] implicitly performs the prefix[sometext] test before removing the specified text.

enjoy,
-e

5 Likes