Tinderbox Forum

Trouble with query in "if" test

I’m trying to create an expression in an “if” condition in export but not having much luck. I have several notes with Children, and I want add certain text to those, but I want to exclude one certain note.

I’ve tried these without luck:

^if(^children^ & $Name!="ZKN")^

^if(!Name(ZKN) & ^children^)^

1 Like

It might be simplest to set $HTMLDontExport of the ZKN note to true.

I want the note to export, I just don’t want this bit of extra text to export with it (basically, the “if” statement controls whether a certain list of links appears on the page or not).

Then try nesting your test

^if(^children^)
     ^if($Name != "ZKN")^
            <do stuff>
     ^endif^
^endif^

There are other approaches.

That works, thanks. Curious, though, why the query can’t accept two statements with the & character.

Answering my own question here, it seems that mixing export codes with regular attribute identifiers is the big no-no. This works:

^if($ChildCount & $Name != "ZKN")^

1 Like

Exactly right: logical operators like & and | aren’t part of the export language.

Love it! This article really helped me on the export filtering piece.

Here is a review of what I’m doing.

I’ve created a method/process for reviewing articles and writing blog articles.

For instance, here is a process I came up with for writing an article I may be be reviewing.

  1. Create a note and assign it to the Article Review Prototype
  2. Create insights (aka notes) as I’m reading the article (See Image 1)
  3. Link the insights to the source (See Image 2)
  4. I then pull everything into the main source note and use $OutlineOrder to specify the order I want the notes to output in the HTML
  5. Next, I refine the article and put in export codes in, like ^value($Name) or ^value($Citation), to pull attributes into the body of the text
  6. I then decide if I want to keep an insight in my final output; if I don’t I check the $HTMLDontExport so that it does not show up in my blog post (See image 3). Note, in my Article Summary HTML template I have a conditional to remove the notes I don’t want to report (See image 4)
  7. I then review the blog post, make any final edits (Image 5); if I’m good to go, I publish it to my blog (Image 6)

I hope someone finds this useful.

Link Action
When I create a link from the source article to the "Insight article I drag over a link or use Link Parking Space. I sent in the Inspector to have that has a Link labeled Insight to trigger this code:

    $Citation(destination)=$Citation(source);
    $StartDate(destination)=$StartDate(source);
    $Type(destination)=$Type(destination)+"Insight";
    if($Name(destination).contains("%")){
       $Type(destination)=$Type(destination)+"Statistic";
   }

This passes over the $Citation and $StartDate details from the source to the insight (I love StartDate to use in the Timeline). It also tags the note as Insight, and tests if there is a % in the title of the destination, if there I tag the destination with as a Statistic as well to help later with agents.

2020-09-13_21-56-05

HTML Export
I pulled form the comments above to use $HTMLDontExport to help with my publishing,
My HTML Template

     ^if(^children^)^
        ^if($HTMLDontExport==false)^
            < h2>^title^< /h2>
     		^text^
     		^children("/Templates/HTML page/HTML item")^
        }
         ^endif^
       ^endif^

Image 1:

!

Image 2:
2020-09-13_22-07-08|690x484 !

Image 3:
2020-09-13_22-18-28

Image 4:
2020-09-13_22-10-07|690x484

Image 5:
2020-09-13_22-22-28

Image 6:
2020-09-13_22-13-58

2 Likes

Thanks for sharing. I’ve fixed the formatting of the code samples and fixed some errors . The erroneous code syntax likely works due to support for lecagy code in old TBX. Way back, export/action code has far fewer options and could be written pretty much in free-text. As the code has got more capable/complex the scope for mis-parsing intent grows.

In the case of export code, I’d recommend to learners that they close export codes with a ^ as it makes clear to yourself if not the app that you understand where codes start/stop. In export code I’ve learned to quote paths to templates, notwithstanding action code practice, but that may be because at some point is did matter. I did a bit more correction here:

^if(^children^)
        ^if($HTMLDontExport=False)^

In queries the equality test is ==, a = only works on a legacy basis. Also boolean values are case-sensitive true and false. My hunch is the code works here on a legacy call back but with coercion of type value there is a possibility of “False” coercing to a true. Why? A false string would be empty, so
“False” is a string with content so, true. This is why it is a good idea to use the current correct syntax against the day when legacy support doesn’t ‘just work’ as expected. :slight_smile:

On a general note, thanks for taking the time to share your workflow description.

I meant to add, you could use one conditional for your second code example. Inside the ^if()^ parentheses, the code is (action query code) so:

^if(^children^)
        ^if($HTMLDontExport=False)^

could be:

^if($ChildCount & $HTMLDontExport==false)^...

It isn’t incorrect to use ^children^ in an ^if()^ and it used to be the approach. But since query language died circe Tinderbox v4 and because action code, and the export code list was thinned in v5, the norm is to use action code in both export if(query)^ and action if(query) conditional queries.

Un picking the latter further, one might think to use ^if(children)^ invoking the children designator. However, designators are not generally used in ‘bare’ form in queries. As you are essentially asking if there are child notes or not, then you can test $ChildCount. Just citing the attribute is the short form test. the following are the same, functionally:

^if($ChildCount)^
^if($ChildCount > 0)^

This is because the default value of a Number-type attribute such as $ChildCount is 0. Type coercion in a query context means 0true and any other value → false.

As queries match individual tests if the test is true, for testing boolean false it is best to use the long form test, i.e. $HTMLDontExport==false. If the test works, the expression is thus true and a match occurs.

Thank you so much! I really appreciate the corrections. :grin::heart:

1 Like

Thanks, it’s hard not to appear pedantic, even if the intent is to help & inform. :slight_smile:

1 Like

I hear you! :slight_smile: It all starts with the intent of the giver, the rest is up to the receiver. Your tireless support in providing this tool and helping people unleash their personal insight is a gift. Thank you.

1 Like