1.
Tinderbox mechanics 1: Export and templates

Table of Contents


Website basics

A website is a set of files and folders that you upload to a file server owned by a web hosting service. The web host makes these files accessible by uploading them to the visitors of your site.

When a visitor types your domain name into the browser address bar, the Domain Name System translates their request into the IP address of the server that hosts your website. The request then goes to the server, and the server sends the appropriate html file to the visitor’s computer. The file uploaded to the visitor’s web browser is a file, on a drive, with a pathname. This file is then rendered by the visitor’s web browser as a web page.

For example, the pathname of the file you are reading right now is

index/Pages/BoxPressLearningCenter/BoxPressReference/Tinderboxmechanics1Expor/Websitebasics.html

The pathname of an html file is called its URL.

What happens when a visitor requests a URL that is just a directory, or a simple domain name (such as mapself.com)? In both cases, the requested URL is a directory (a domain name is just the root directory for a web site). When the requested URL is a directory, there is still a file that the web server serves. This file is called the default page for that directory. On most web servers, the default page name for a directory is index.html.

When you enter http://mapself.com into your address bar, the page you see is actually http://mapself.com/index.html. The default page for your domain name is called the landing page (or front page, or home page) of your website.

The home page will contain links to the other pages of your blog. These are also html files, hopefully arranged in a directory structure that reflects their natural semantic categorization.

Basics of exporting

The final directory structure

The first thing to think about when exporting any kind of website from from Tinderbox is the directory structure you will employ on your server. A blog website must have a certain structure, and your Tinderbox export will have to conform to this structure.

One way to expedite this process is to download a ready-made website directory structure. BoxPress uses the “compiled and minified” Bootstrap framework. The unzipped folder will serve as your Tinderbox export folder, and also the root directory of your website.

When exporting from Tinderbox, the rule is: The containment structure of your TBX becomes the (default) directory structure of your export. The former is made of notes and container notes; the latter, of files and folders.

Tinderbox structure becomes the default directory structure, not the necessary structure. The final export structure can deviate from the Tinderbox containment structure by means of certain tricks:

  • You can turn the export of a note off and on with the flick of a switch. If you the note’s $HTMLDontExport attribute to true, the note will be skipped and its template never applied.
  • You can use the ^include()^ export code to insert the text (or any other attribute) from a distant note.

The Bootstrap distribution will be your export folder

Heads up
The following steps have already been done for you!

  • Your BoxPress download comes with Bootstrap 3.3.5.
  • An images folder (img) has been added.
  • Choose BoxPressDEMO if you want to learn about export and access the documentation images. Choose BoxPressExport if you want to start fresh with no images.

To download the latest Bootstrap distribution, click here:

Bootstrap Downloads

Find the “Compiled and minified CSS, JavaScript, and fonts” option and then click the “Download Bootstrap” button.

Once the file is downloaded, unzip it and you will have somethjing like this:

This is the directory you will be exporting into—a clean and minimal Bootstrap framework.

This is the directory you will be exporting into—a clean and minimal Bootstrap framework.

Now rename the folder to something else, like BoxPressExport. This will be the export folder for your Tinderbox HTML export. To export your blog (and set the default export directory), do File > Export > as HTML, select the export folder, and click the Export button.

You will almost certainly want some of your own images in your blog. To do this, you will need to add an images directory to your export folder. Make a new folder inside your export folder and name it img.

How to export

To a export your entire TBX (the method we will be using to export an entire website), run File > Export > as HTML. Doing this will also set the default location of future individual note exports.

To export an individual target note in Tinderbox, select it and run File > Export Selected Note. When you execute the export, only the selected note will be exported—not its children, and not anything else.

Tinderbox will guess the right location, which is important since CSS and images are read from the current note. If the export location of the current note is impossible because the sub-folder has not yet been created, the export will look screwy.

In any case, make sure you select the root of the Bootstrap framework folder you downloaded and unzipped as your export folder.

The only way to export more than one note at a time is to export your entire TBX.

Badges show export settings

There are two attributes that control HTML export—$HTMLDontExport and $HTMLExportChildren:

  • $HTMLDontExport—If this is true, then the note will not export as a file. However, it will still export as a folder if it has children that are exported as files.
  • $HTMLExportChildren—If this is false, then none the note’s descendants will be exported (as a file, inside an isomorphic directory structure). If this is true, then the children may or may not export, depending on the value of their $HTMLDontExport attribute.

There are four possible export permutations here:

  • Note and children
  • Note and no children
  • No note but children
  • No note and no children

To indicate which of these holds, BoxPress has an agent that change the appearance of notes where knowing which is these four holds of a note is useful—inside BlogTopNote and inside CSS:

Two places where knowing export settings is noteworthy—BlogTopNote, CSS, and their respective children.

Two places where knowing export settings is noteworthy—BlogTopNote, CSS, and their respective children.

The meanings of the badges is shown in the following legend:

Export status badges and their meanings.

Export status badges and their meanings.

(By the way—none of the notes you see here will ever be touched. They are the framework of your website. Your content notes are written inside the two content containers, BlogPAGES and BlogPOSTS. Or you can use the sandbox container, called ALL_NOTES.)

TBX structure and exported directory structure

The isomorphism is only partial

The exported file structure

Here is what the exported file structure of your BoxPress blog will look like:

BoxPressExport/
  css/
  fonts/
  img/
  index/
    About/
    Pages/
    Posts/
    404.html
    About.html
    Archives.html
    Categories.html
    Pages.html
  js/
  index.html
The exported directory structure of your blog.

The exported directory structure of your blog.

The TBX note structure

While the corresponding structure inside your BoxPress TBX looks like this:

BlogTopNote
  BlogPAGES/
  BlogPOSTS/
  BlogNavBar/
  BlogAboutNote/
  Blog404
  BlogHome
  BlogArchives
  BlogCategories
  Dashboard
  TEMPLATES
  BOILERPLATE
CSS
Prototypes
Adornments
UTILITY
ALL_NOTES
Simplenote
The internal container structure of your TBX file. Note that there are only seven notes at root level.

The internal container structure of your TBX file. Note that there are only seven notes at root level.

The relation between the two can be neatly displayed in a table:

Table of correspondences
BoxPress noteExported file
BlogTopNoteindex.html and the index folder
BlogPAGES/Pages.html and the Pages folder
BlogPOSTS/the Posts folder
BlogNavBar/[children included as navbar buttons]
BlogAboutNote/About.html
Blog404404.html
BlogHome[children included as teasers on home-page]
BlogArchivesArchives.html
BlogCategoriesCategories.html
CSSthe css folder
blog-mainblog-main.css
blog-extrablog-extra.css

The seven topmost (root) notes

There are seven topmost notes in your BoxPress TBX root: BlogTopNote, CSS, BOILERPLATE, UTILITY, Prototypes, ALL_NOTES, and Simplenote.

  1. The BlogTopNote container note will be exported as index.html in the root of your export folder and will serve as your landing or home page. It will be the typical blog front page—i.e., it will display truncated excerpts of the six (or n) most recent posts. Since BlogTopNote contains other notes, it will also export as a folder (named index). The index folder will hold all of your webpages. Note that BlogTopNote will change its display name after you set things up in the Styles Dash. (For a detailed analysis, see below: A closer look inside blogTopNote.)
  2. The CSS note will export as the css folder (renamed to lowercase) in the root of your export folder. Don’t worry if a folder called css already exists, exporting will merely add to the files already there.
  3. The Prototypes container is now here in order to comply with the new automatic prototype generation in TinderboxSix. All your prototypes are here.
  4. The Adornments container gives adornments their own container. Why? Because it takes a ridiculous amount of time for Tinderbox to load prototypes into Map View, and you can only modify adornments in Map View.
  5. The UTILITY container note will not be exported. It contains agents, prototypes, code, and technical extras for your whole TBX.
  6. The research/sandbox area in BoxPress is called ALL_NOTES. Inside are massively large categories—projects, to-do lists, yogurt fermentation timelines, my 5 year plan, my inbox, etc. It also contains collections of quotations. Nothing inside the ALL_NOTES container will be exported. It’s a place to put all of your contentful writing. When you write anything, it goes here first. When a note (or note bundle) is ready for exporting, move it inside a category note and check its $blogReady attribute.
  7. Finally, there is Simplenote. A note with this name is required if your TBX is to sync with Simplenote, the free mobile writing app. This lets you add notes from your phone so you can graph your workout progress. It’s a great feature so I included it.

The badges you see here automatically update via an agent. These are the only notes whose badges are used up. Because seeing export structure alongside the names here gives you insight into the form of the website.

A closer look inside blogTopNote

The topmost BlogTopNote note contains seven notes and three agents:

BlogTopNote/
  BlogPAGES
  BlogPOSTS
  BlogNAVBAR
  BlogAboutNote
  Blog404
  BlogHome
  BlogArchives
  BlogCategories
  Dashboard
  TEMPLATES
  BOILERPLATE
BlogTopNote and its contents. Never change these notes’ actual $Name. To set the name of BlogTopNote, use the Styles Dash. To set the name of BlogAboutNote, change its $DisplayExpression.

BlogTopNote and its contents. Never change these notes’ actual $Name. To set the name of BlogTopNote, use the Styles Dash. To set the name of BlogAboutNote, change its $DisplayExpression.

The notes that are not exported are BlogNavbar, @Home, Dashboard, TEMPLATES, and BOILERPLATE.

The other notes do get exported—to produce index.html along with the index folder and its contents:

index
  Pages/
  Posts/
  404.html
  About.html
  Archives.html
  Categories.html
  Pages.html

BlogTopNote → index.html and index/

BlogPOSTS → Posts/

BlogPAGES → Pages.html and Pages/

BlogNavBar [diverted to navbar]

BlogAboutNote → About.html

Blog404 → 404.html

BlogHome [included in index.html]

BlogArchives → Archives.html

BlogCategories → Categories.html

TEMPLATES

BOILERPLATE

BoxPress special webpages

Important
The names of the BoxPress special webpages should never be changed. Their names are odd in order to keep them unique, for the sake of reference. Do not use these odd names for any of your own notes.

The Home webpage

The Pages webpage

The About webpage

The 404 webpage

The Archives webpage

The Categories webpage

cat_note webpages

Ordinary content webpages

About export templates

You can see from the image above that the BlogTopNote note is empty (its icon is short). How can an empty note get exported as your landing page, index.html? It’s possible because the content of any exported note is determined by the export template you have assigned to it. Whenever you export a note, you must use an export template.

How to export
To export a target note in Tinderbox, select it and run File > Export Selected Note. To a export your entire TBX (and an entire website), run File > Export > as HTML.

Select BlogTopNote (whose display name is probably something else by now if you’ve used the Style Dash) and click the HTML tab of the Text Pane Selector to view the HTML destined for export.

Here’s the markup version of your note.

Here’s the markup version of your note.

Even though the note is empty, you can see that it’s export is not. This is because it is the content of the export template that is the primary content of the export. The content of the note you are exporting (the target note) finds its way into the final output only where the Tinderbox export code tells it to.

A Tinderbox export template is any note that you designate as a template by setting its $IsTemplate attribute to true.

Example 1: Text derives from the target note

We can better understand how Tinderbox exports a target note with an example. Let’s say our target note is the following:

TargetNote

This is the main target note we want to export and here’s its content!

Now let’s say you want to export TargetNote with a template that contains only the text "Hello Dolly!"

TemplateOne

Hello Dolly!

The final output would then be

Hello Dolly!

In fact, every target note that you export with TemplateOne will be rendered this way no matter what the target note may actually contain.

Of course, a template is useful precisely because it incorporates the content from other notes. For example, to export the rich text of a note, your template would include the export code ^text^. So if I exported our target note above with a template note that contained this:

TemplateTwo

This is a template note. This could be some header material. And below this line we shall open a wormhole to the note we are actually exporting:

^text^

And here we can cap it off with some footer material.

The resulting exported file will contain this:

This is a template note. This could be some header material. And below this line we shall open a wormhole to the note we are actually exporting:

This is the main target note we want to export and here’s its content!

And here we can cap it off with some footer material.

In this example the template simply delivered the rich text of the content note and surrounded it with a bit of boilerplate. But a template can also determine how you style that content. It can also change that content according to conditions. And it can also include content from the other 250 attributes that a note has besides its $Text.

Example 2: Text included from other notes

Imagine that a template note contained this:

TemplateThree

This is another template note.

^include(TopNote)^

^text^

^include(BottomNote)^

Have a great day!

And let’s say that our TBX also contained the following two notes:

TopNote

Here’s some text from TopNote.

and

BottomNote

Here’s some text from BottomNote.

Now, let’s use TemplateThree to export TargetNote. The result would be this:

This is another template note.

Here’s some text from TopNote.

This is the main target note we want to export and here’s its content!

Here’s some text from BottomNote.

Have a great day!

Thus, by using the ^include()^ export code, you can include content from others notes in your export.

But you can also place an ^include()^ directly inside a content note. I often do this with text (such as lists) that I frequently refer to.

The minimal template for a web page

In making a blog, all our files will be in HTML—a mix of the textual content people actually read with the HTML elements (code) that arrange the visual bed of that content. So we should expect our basic blog template to bear some resemblance to this:

<!DOCTYPE html>
<html>
  <head>
    <title>^title^</title>
  </head>
  <body>
    <p>^text^</p>
  </body>
</html>

About boilerplate

An HTML web page contains four parts:

  • Doctype
  • html root element
  • <head> section
  • <body> section

The bsbTop boilerplate contains the Doctype, <html> root element, <head> section, and just the topmost parts of the <body> section—the navbar and the large Banner with your blog title and description.

The next section of the bstMainPage template lays out the main .container div of your blog page—everything under the Banner and above the footer. This is the Bootstrap responsive element—it varies its width discretely according to the width of the browser window. (To make this variation fluid, change class=container to class=container-fluid).

Immediately inside this is another div, the .row. A Bootstrap .row div is what allows you to use the Bootstrap predefined grid (column) system. Grid columns are created by specifying the number of twelve available columns you wish to span.

There are four classes prefixes: col-xs-, .col-sm-, .col-md-, .col-lg. Columns in xs are always preserved, while those in the others fall back on the setting for the smaller size. If nothing is set for the smaller size, the divs become collapsed-and-stacked.

The columns are laid out in this line of HTML:

<main class="col-sm-8 col-main">

This means that the main area of your blog body (all the stuff on the left) is 8 (out of 12) columns wide.

After the main line, the bstMainPage template begins checking the nature of each note up for export.

Grid system rules

Some Bootstrap grid system rules:

  • Rows must be placed within a .container (fixed-width) or .container-fluid (full-width) for proper alignment and padding
  • Use rows to create horizontal groups of columns
  • Content should be placed within columns, and only columns may be immediate children of rows
  • Predefined classes like .row and .col-sm-4 are available for quickly making grid layouts
  • Columns create gutters (gaps between column content) via padding. That padding is offset in rows for the first and last column via negative margin on .rows
  • Grid columns are created by specifying the number of 12 available columns you wish to span. For example, three equal columns would use three .col-sm-4

About the Bootstrap grid system

To use the grid system, make a

. Now you have a row that is secretly a grid that is 12 squares across. If you make a div inside of this, it will be 12/12 squares across—the full width. But the point of the invisible squares is to make divs that span less than 12 squares across. Moreover, you can have the spans change automatically with the browser width.

Table: Bootstrap grid for Tinderboxers
PrefixMeaning
.col-xs-width = N/12 when container wider than 0
.col-sm-width = N/12 when container wider than 768px
.col-md-width = N/12 when container wider than 992px
.col-lg-width = N/12 when container wider than 1200px

Next concept: you can combine these.

<div class="row">
  <div class="col-xs-6 col-sm-4">.col-xs-6 .col-sm-4</div>
  <div class="col-xs-6 col-sm-4">.col-xs-6 .col-sm-4</div>
</div>

This means: “When the browser is wider than 768px, each div is half-way across; when less than 768px, a third-way across.”

There is a hierarchy of precedence here. If the container is < lg, Bootstrap falls back on whatever you’ve set for md. If md has not been set, it looks at sm. If sm not set, then it looks to your setting for xs. If that is not set, the divs are stacked vertically.

Brief analysis of bstMainPage

bstMainPage is the default template file for BoxPress. The template that a note uses during export is determined by the value of its $HTMLTemplateFile attribute. BoxPress has been set up to export every page in your website with the bstMainPage template. Unless you set the value of $HTMLTemplateFile to something else, the default value of the $HTMLTemplateFile system attribute will be the one found in the local file Preferences. This has already been set for you.

How to set the default template in TB5
To set the default template for your whole TBX, hit ⌘8 to open the local file Preferences, click the HTML tab, and set the “HTML template file” field.
How to set the default template in TB6+
To set the default template for your whole TBX, go to Document Inspector > System > HTML > HTMLExportTemplate and enter the path of your preferred template note in the “Default” field.

An individual note’s $HTMLTemplateFile can be changed in various ways:

  • In the Get Info window: ⌥⌘I
  • In the HTML Inspector
  • Using an agent
  • Using a rule

What does the bstMainPage template do?

  • It inserts some boilerplate.
  • It checks to see if the post has an HTML imagemap and, if so, inserts the appropriate boilerplate.
  • It lays out a responsive .container div and a .row that can be treated as a 12-column grid (features inherited from the Bootstrap framework).
  • It lays out the HTML5 main element, and gives the left 8 columns to your main content.
  • It makes queries about the target note. Is it our BlogTopNote? Is it the BlogAboutNote? It is the Categories agent? It is the Archives agent? Is it one of your category container notes? Is it the PAGES container note? If so, then do something special. If not, then assume that it’s a post and include the note using the bstPost template.
  • It closes the 8-column main element.
  • It inserts more boilerplate—bsbSidebar.
  • It closes the .container div and the .row main elements.
  • It inserts the final bit of boilerplate—bsbBottom.

Controlling export with agents

When you export your entire TBX using File > Export > as HTML, bstMainPage is applied to every content note of your TBX. It’s a universal application of a set of templates to all your notes. Templates can be assigned by prototypal inheritance, and this turns out to be a functional logical division.

All this is the same for every note that gets exported. Notes are exported according to $OutlineOrder, and container notes are processed recursively. But some notes will be passed over, and this is good—it saves time. Notes whose $HTMLDontExport is true will be passed over.

BoxPress has an agent that sets $HTMLDontExport for you automatically—the @export POSTS/PAGES agent. The notes up for consideration? Here’s the $AgentQuery:

descendedFrom("BlogPOSTS") & ($OutlineDepth(original)=4)

This says that every note descended from BlogPAGES and BlogPOSTS whose prototype is normal_note will be collected for consideration.

Then, the $AgentAction that will be applied to this collection:

if($blogReady & $blogExpOpt!="include"){$HTMLDontExport=;$Color=;}else{$HTMLDontExport=1;$Color="dark _norm";};

The default value of $blogReady is false—which means that all sub-posts will export unless $blogExpOpt has been set to either SKIP or FOOTNOTE. This default value also means that every post requires your explicit consent—a prophylactic against accidental private note taking.