Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Exporting from Tinderbox >> ^format()^ problem and html export
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1332266129

Message started by james a. foster on Mar 20th, 2012, 1:55pm

Title: ^format()^ problem and html export
Post by james a. foster on 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?

Title: Re: ^format()^ problem and html export
Post by Mark Bernstein on 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")


Title: Re: ^format()^ problem and html export
Post by james a. foster on Mar 20th, 2012, 2:47pm

There was no space, but I'll try ^value

Title: Re: ^format()^ problem and html export
Post by Mark Anderson on 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!).

Title: Re: ^format()^ problem and html export
Post by james a. foster on 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.

Title: Re: ^format()^ problem and html export
Post by Mark Anderson on 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.

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.