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
^format()^ problem and html export (Read 9122 times)
james a. foster
Full Member
*
Offline



Posts: 130

^format()^ problem and html export
Mar 20th, 2012, 1:55pm
 
I have a note with the following text, and export to html with the plain style:

this is today, I think: ^format( ^today^,"L") )^
And this is the creation date: ^format( $Created, "L")^

And this is my output:


<!--   ** Standard Tinderbox Template [plain] **  -->
<h2>Test export codes</h2>
<p>this is today, I think: ^ format( ^today^,"L") )^</p>
<p>And this is the creation date: ^ format( $Created, "L")</p>

Why don't I just get a couple dates in the output? Why the carat symbols?
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: ^format()^ problem and html export
Reply #1 - Mar 20th, 2012, 2:19pm
 
First, it looks like there's a space after the caret. Export commands must not have any white space after the caret.

But the old ^format() element has been replaced by the much more flexible ^value() element. A stray reference to the old way of doing things remained in the manual, and will be corrected in the next release.

    old:  ^format( date-attribute, format-string)

   new: ^value (format(date-expression,format-string))

The new way of doing things is slightly more verbose, but it has many advantages -- most notably, you can use any expression that results in a date.  For example

     ^value(format(date("tomorrow"),"L")

Back to top
 
« Last Edit: Mar 20th, 2012, 2:30pm by Mark Bernstein »  
WWW   IP Logged
james a. foster
Full Member
*
Offline



Posts: 130

Re: ^format()^ problem and html export
Reply #2 - Mar 20th, 2012, 2:47pm
 
There was no space, but I'll try ^value
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: ^format()^ problem and html export
Reply #3 - Mar 20th, 2012, 2:55pm
 
James' ^format()^ example has no space after the opening caret but it you test it in a template one appears. This is TB telling you, without an error code, that there is no such export command format() - it assumes you meant something else so inserts a space to stop the code that follows the initial caret from being interpreted (and causing Tb further headache. Instead it skips on to the next - correct - export code.

In fact, the original export code equivalent of the action code format() was done via ^get()^ and ^getFor^ but these two are depracted in favour of ^value()^ wrapping the necessary formatting action code. You can use either format() or the dot-notation.format() for your dates:

  ^value(format(date("tomorrow"),"L")^
  ^value(format(date($Created),"L")^

vs.
  ^value(date("tomorrow").format("L"))^
  ^value($Created.format("L"))^


Both forms work with the dot-notation version being newer and - once you get the concept of it - the more flexible and intuitive to use. Think of ^value()^ as "insert value here" with the contents of the parentheses being either an attribute reference or some action code expression that results in a string - which becomes the string inserted into the exported file.

See aTbRef for the most up-to-date listing of export codes, which are now deprecated and what replaces them. If you know a code and its not listed here, most likely it's deprecated so see this list; I'm just editing aTbRef to make those two lists better cross-referred (later: done!).
Back to top
 
« Last Edit: Mar 20th, 2012, 3:12pm by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
james a. foster
Full Member
*
Offline



Posts: 130

Re: ^format()^ problem and html export
Reply #4 - Mar 21st, 2012, 4:56pm
 
There is a good tip hidden in this thread:

NEVER have a space after the ^ in an export code. That way, if your code is ill-formed TBX will insert a space in the exported text. That means that any occurrence of "^ " indicates an error in your original export code.

But of course, that assumes you NEVER put a space after a caret.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: ^format()^ problem and html export
Reply #5 - Mar 21st, 2012, 5:35pm
 
You probably want to read this page too. I think it underscores the importance of always closing your ^codes^ with a caret even though the latter is optional.
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