Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Conditional tests to export links (Read 6186 times)
Paul Walters
Ex Member




Conditional tests to export links
Sep 01st, 2008, 9:08pm
 
In HTML export I want to include a div for inbound links to a note and a div for outbound links, conditioned on whether such links exist.  I am performing conditional tests in the export template, wrapped around the div code.

The test

Code:
^if(^exists(basicLinks)^)^ 



evaluates as true or false, depending upon whether there exists outbound basic links from a note.

whereas

Code:
^if(^exists(inboundBasicLinks)^)^ 



apparently always evaluates as true.  And so, that div appears in the export whether or not there are, in fact, inbound basic links.  (The same occurs when I test inboundLinkCount - apparently it is always true.)

Is there a better test?
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Conditional tests to export links
Reply #1 - Sep 2nd, 2008, 3:22am
 
You're assessing the export code ^basicLinks^ & ^inboundBasicLinks^ but not using the carets.  Before looking at anything else, I'd change the code to:
Code:
if(^exists(^basicLinks^)^)^
...and...
^if(^exists(^inboundBasicLinks^)^)^ 


Otherwise, you may be assessing false positives/negatives.  There may still be a problem to overcome but it should be the right one. In learning TB I tripped over this a fair bit to start - the fact that code errors can still get coerced to a Boolean result, albeit a false one (no pun intended!).

On a general note for all those reading this, export codes names are case insensitive but TB usage custom is to write them intercapitalised to help distinguish them from action codes (normally all lowercase), attributes (normally both capitalised and intercapitalised), etc. Closing carets (^) on export codes are also optional but encouraged, especially during troubleshooting like this as they tell TB where the code ends rather than leaving the app to guess (almost always correctly, it should be said).
Back to top
 
« Last Edit: Sep 2nd, 2008, 4:39am by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Paul Walters
Ex Member




Re: Conditional tests to export links
Reply #2 - Sep 2nd, 2008, 5:30am
 
Well, I tried

Code:
^if(^exists(^basicLinks^)^)^ ...and... ^if(^exists(^inboundBasicLinks^)^)^ 



and nothing was exported.

Later, I found a note in the TB wiki from Eric Abrahamsen (at http://www.eastgate.com/wiki2/wiki.cgi?TestingIfConditions) suggesting the following tests, which worked for me too:

Code:
 ^if(basicLinks)^ ... and ... ^if(inboundBasicLinks)^ 

Back to top
 
« Last Edit: Sep 2nd, 2008, 8:46am by Paul Walters »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Conditional tests to export links
Reply #3 - Sep 2nd, 2008, 9:28am
 
Now I'm reminded, the very last paragraph of the wiki page you cited helps explain - if at all - that the issues is one of testing a condition exists vs a query where matches are found or not.  As the aTbRef page for ^exists()^ notes, this tests either:
  • existence of an item object.
  • a non-empty attribute value.
Of course, a populated Export code (for links) is neither of the above.  The 'error', insofar as there is one, is using the wrong test - i.e. ^exists^.  

The successful ^if(basicLinks)...etc. usage is employing (undocumented) situation whereby if the code has links then that fact is coerced to a 'true' Bolean result; note though the scope for false positives when relying on a feature not fully laid bare.  I've not time to build a full test rig but I think that your test ought to be ^if(^basicLinks^)...etc., and that luckily TB is figuring that you're trying to test the ^basicLinks^ export code and not something else. Interestingly, I note that cited wiki page's first problem was partly due to not using closing carets!

Again to help any lurkers wading through this the following are probably all parsed as the same thing by Tinderbox:
  • ^if(basicLinks)
  • ^if(^basicLinks)
  • ^if(^basicLinks^)
  • ^if(^basicLinks()^)
  • ... and doubtless other variations.  Where argument(s) to a code are optional, the brackets may be ommited.
In the case of basicLinks, the default list HTML is used if no arguments are provided. Simple to use...once you know how.

This reminds me that there's currently no good learner's article on coercion in if tests. It's something that's unintuitive to non-programming types.

Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print