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
Implicit truth testing with ^value (Read 6420 times)
Ioa Petra-ka
Full Member
*
Offline



Posts: 103
Portland, Oregon, USA
Implicit truth testing with ^value
Jan 16th, 2010, 5:19pm
 
Something that probably ought to mentioned in the documentation is that the new `^value` template code does not return true or false depending on the attribute state. It is described as being essentially synonymous with `^get[For]`, but in that one aspect it is not. The following used to return false if the attribute was “empty” according the rules of `^exists`:

Code:
^if(^get(SomeAttribute)^)^ 



…but

Code:
^if(^value($SomeAttribute)^)^ 



…does not.

Perhaps I was a bit of an eccentric in that I used this method for truth testing, but it might deserve mention that `^exists` is now the preferred syntax for this type of simple conditional. And that old templates will need to be adjusted accordingly.

Update: Another peculiarity I’m running into is that `^exists` doesn’t seem to work with all data types. For instance, with sets it returns truth even if the set is empty. It seems the only “simple” way to test for false or empty sets is to continue using the old `^get` method.
Back to top
 
« Last Edit: Jan 16th, 2010, 10:02pm by Ioa Petra-ka »  

Av
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Implicate truth testing with ^value
Reply #1 - Jan 16th, 2010, 5:53pm
 
True, but regarding your first example a more normal export-code-based conditional is:
^if(MyString)^^get(MyString)^^else^Stuff^endIf^

IOW, ^if(MyString)^ not ^if(^get(MyString)^)^.

That said, agree that different outcomes from attribute name or ^get conditionals and ^value conditionals it would be worth noting. Probably one for submission to the cookbook too.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Ioa Petra-ka
Full Member
*
Offline



Posts: 103
Portland, Oregon, USA
Re: Implicit truth testing with ^value
Reply #2 - Jan 16th, 2010, 10:20pm
 
Yes, I don't remember why I started using the more expanded version. Perhaps at some point (circa v3), using ^get was safer for all data types or something and I just got into the habit of it.
Back to top
 
 

Av
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Implicit truth testing with ^value
Reply #3 - Jan 17th, 2010, 8:47am
 
Testing sets as bare attribute name works for tests, even if exists doesn't; use a $ prefix if in action code.

These suggested positive/negative match export syntaxes for sets:
 ^if(MySet)^truth^else^not truth^endIf^
 ^if(!MySet)^truth^else^not truth^endIf^
 ^if(^not(MySet)^)^truth^else^not truth^endIf^

…both work. I suggest changing your code to the above with the '!' syntax being the preferred negative test form as it better mirrors internal syntax.
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