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
Export template "if" generates extra line return (Read 4692 times)
Sumner Gerard
Full Member
*
Offline



Posts: 359

Export template "if" generates extra line return
Aug 25th, 2010, 11:08pm
 
The SIMILE timeline example on the Tinderbox Exchange exports an xml data file with "blank lines" where the "if" statements in the export template evaluate as false.  How does one suppress the extra line return?  

For example, I've now got:

<event
start="^value(format($StartDate,*))^"
^if($EndDate)^end="^value(format($EndDate,*))^"^endif^
>^text^
</event>


Which gives nice looking output when there is both a StartDate and an EndDate, but insists on inserting a blank line when there is no EndDate. Timeline minds the extra white space less than I do, of course, but after looking with admiration at http://www.alexstrick.com/timeline/ I know it's possible to export compact xml.  (And presumably SIMILE Exhibit's native JSON format too).
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Export template "if" generates extra line return
Reply #1 - Aug 26th, 2010, 3:55am
 
Once you start to use branching in export you hit an dichotomy between tidy, easy to read TB code and tidy HTML output. TB will output a line break in HTML (XML, etc...) source for each line break in your template. So if a line only has ^code^ you'll get a blank line. As a simple example , instead of:
Code:
^if($SomeBoolean)^
<br/>
^else^
<hr/>
^endIf^ 


Use:
Code:
^if($SomeBoolean)^<br/>^else^<hr/>^endIf^ 


A method I use with complex if clauses is to use the former layout whilst getting the rendered HTML, and attribute content correct and only then edit out the TB template line breaks.

The Kandahar timeline was created from a TBX I made as part of some TB consulting work so at this point I can't post the file publicly. However, Alex Strick has graciously indicated that a community resource version of the TBX would be OK - so at some point....

Alex's project was an interesting challenge as I've made the TBX export not just the events data, but the configuration JS as well as a few libraries fixing bugs/annoyances in the current SIMILE code. I also had to allow for the fact that Kandahar, where the author is based, isn't the most online place on the globe so the TBX allows for online and local offline use (latter for testing, presentations, etc.). The resulting TBX makes a it easy for a non HTML/JS/CSS/XML coder to simply make a timeline by filling in the data (and reading the documentation notes I've supplied).
Back to top
 
 

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



Posts: 359

Re: Export template "if" generates extra line return
Reply #2 - Aug 26th, 2010, 8:27am
 
Thanks, Mark.  The Kandahar chronology is great.  

I understand about getting an export template working first and then editing to reduce white space as desired.

But in my example above (and the example on the Exchange) how does one avoid the EXTRA line break when the "if" evaluates as false?
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Export template "if" generates extra line return
Reply #3 - Aug 26th, 2010, 9:02am
 
OK so you want either:
Code:
<event
start="date"
end="date"
>blah blah
</event> 


or
Code:
<event
start="date"
>blah blah
</event> 


but in the latter case you're getting:
Code:
<event
start="date"

>blah blah
</event> 


If so, you need to put the second line break inside the 'else' branch:
Code:
<event
start="^value(format($StartDate,*))^"
^if($EndDate)^end="^value(format($EndDate,*))^"
^endif^>^text^
</event> 


This code gives the first two examples above. Look at the line break placement to see why. As per my earlier answer - you can't (for now anyway) have both 'tidy' ^code^ and formatted output. If the template example above 'looks' wrong when in TB, use the iterative method suggested. Get the right data output then tweak the template to get the output layout you want. I empathise more than you might think - I do all my web coding by 'hand' and care about having a good code layout - debugging machine written mark-up is nightmarish.
Back to top
 
 

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



Posts: 359

Re: Export template "if" generates extra line return
Reply #4 - Aug 26th, 2010, 12:01pm
 
Ah, so to produce a line break (but no blank line when the "if" evaluates as false) it seems that the line break in the template has to come before the ^endif^ and there can be no line break after ^endif^.  

Haven't internalized exactly why that is so, but probably don't need to. The iterative method pointers are very helpful, and get the job done.  Thanks!
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Export template "if" generates extra line return
Reply #5 - Aug 26th, 2010, 1:26pm
 
By moving the line end for the 'end' attribute before the ^endIf^ its is only exported if the ^if^ condition is met. Otherwise, the line end after the 'start' attribute is followed by the > closing the <event> tag. If you're polishing your output layout be very attentive to placement of line breaks near ^if()^, ^else^ and ^endIf^.
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