Leonard Richardson <leonardr@segfault.org>
NewsBruiser has a simple templating system that allows you to customize the look of your entries on a per-notebook basis without changing the NewsBruiser code. If you can't make your entries look the way you want with CSS, you should be able to do it by changing the templates.
All of NewsBruiser's templates are editable under the "Layout Templates" and "Entry Templates" section of the configure screen (follow the "Configure" link from the notebook index and then the "Layout Templates" or "Entry Templates" link).
If you don't like editing the NewsBruiser templates from the Web, you can change any template value to the string "file:" plus the path to a file on disk, for example: file:templates/entry.template. NewsBruiser will read that file (it looks for it under the directory in which you installed NewsBruiser) and use its contents as the template string. This lets you edit the templates with a text editor on the web server, upload them from your home computer with scp, or whatever else you might want to do.
NewsBruiser templates consist of HTML interspersed with template directives. All template directives consist of a percent sign and a directive of one or more characters, for instance: %a or %CP or %url-currentMonth. When a template is interpolated for an entry, its directives are replaced with the appropriate values for that entry (see a template's documentation below for a list of the valid directives for that template).
If you need a literal percent sign in your template (for instance,
when expressing the width of a table element as a percent), you can
use '%%'. NewsBruiser will not interpolate directives it doesn't
recognize, so you don't need to use '%%' unless the character after
your percent sign is a valid NewsBruiser directive character.
General directive information
In general, lowercase and non-alphabetic directives apply directly to the object being interpolated (for instance, an entry). Uppercase directives in a template trigger the interpolation of another template (if appropriate to the object being interpolated). There are a few exceptions to this rule, mostly required for compatibility with the strtime format.
All templates recognize the following notebook-specific directives:
These templates let you customize the general layout of NewsBruiser.
This template controls the HTML that gets rendered at the beginning of every page you visit. You can use it to create a global look and feel. It recognizes the following special template directives, and you really should use all of them:
This template controls the HTML that gets rendered at the end of every page you visit. You can use it to create a global look and feel. It recognizes the following special template directives, the first of which you really should be sure to use:
This template controls the HTML that gets rendered when you visit the main page of your NewsBruiser installation. It can call the entry list template as well as use the following directives:
This template is interpolated whenever the %notebook-archive-monthly directive is encountered. It's basically a wrapper around each archive link so that you can put each link on its own line or table cell. It must include the %link directive (which prints an actual archive link), and it can't include any other directives.
This template is interpolated when the %panel-blogroll directive is encountered and when there are links in the blogroll. It must include the %notebook-blogroll directive.
This template is interpolated for each item in the blogroll when the %notebook-blogroll directive is encountered. It's basically a wrapper around each blogroll so that you can put each link on its own line or table cell. It must include the %link directive (which prints the actual link link), and it can't include any other directives.
This template is generally interpolated from the main page template. It should consist of the %links-reader directive, wrapped around whatever HTML is neccessary to mantain consistency with the main page template.
This template is generally interpolated from the main page template. It should consist of the %searchBox directive, wrapped around whatever HTML is neccessary to mantain consistency with the main page template.
You can put this in your header or footer template to display summaries of the most recent items in your summary list. It is baiscally a mini-entry list template. It accepts the entry template directives as well as the following special directive:
There are two of these; one for Creative Commons-compatible licenses and one for all other licenses (including full copyright). They can make use of all the basic template commands (notebook-yearSpan is especially useful), as well as the following one:
When you call the Creative Commons license template, in addition to what you specified in the template you'll get some RDF enclosed in an HTML comment. This machine-readable code will help search engines and other tools know about the terms under which your notebook is licensed. It won't be visible or affect the way your notebook looks at all.
These templates are interpolated in the context of a specific list of entries being rendered as HTML, whether the entries be a list of recent entries, the contents of a dated archive, a list of search results, a list of random entries, or anything else.
The entry list template is the 'master' template, which indirectly or directly includes every other NewsBruiser template. The entry list template is used to display notebook entries on the screens view, edit, search, and category, the this_month.ssi SSI, etc. etc. Anywhere a notebook entry is rendered as HTML, the entry list template is being processed.
You have two choices for the entry template. You can invoke %E directive directly and print out all the entries in the current entry list one after another. Alternatively, you can group the entries by year, month, or day by interpolating one of the timespan templates. The latter option allows you to (e.g.) print separators distinguishing different months, or to put each day's entries in their own table.
The entry list template recognizes the following directives:
The entry list template is useful for specifying opening and closing HTML for your entry list. For instance, if you wanted every entry in an entry list to be part of an ordered HTML list, you could set your entry template to this:
<ol>%E</ol>
And set your entry template to (something like) this:
<li>%d: %e</li>
The "Poindexter" theme provides an example of HTML in the entry list.
The "Sobelow" theme provides an example of the date span templates.
Timespan templates
The year span template is interpolated once for every year in a list of entries. It must contain the '%M' directive.
The year span template recognizes the following directives:
The month span template is interpolated once for every year in a list of entries (if interpolated from the entry template), or once for every month in a year of entries (if interpolated from the year span template). It must contain the '%D' directive.
The month span template recognizes the following directives:
The day span template is interpolated once for every day in a list of entries (if interpolated from the entry template), or once for every day in a month of entries (if interpolated from the day span template). It must contain the '%E' directive.
The month span template recognizes the following directives:
The following directives can be used in the entry template or any of its subtemplates:
The entry template is used to display one of the notebook entries in a list. It is called whenever the %E directive is found in the entry list template.
The entry template recognizes the following special directives:
The default entry template is as follows:
<p class="entry">%p <a name="%i" class="entryDate">%d</a>%A%T: <span class="entryText">%e</span></p>
If you want the same, but you want to alternate background colors for your entries, then uncomment the background-color attributes of the .entry2 directive in default.css and try this:
<p class="entry%2>%p <a name="%i" class="entryDate" width="100%">%d</a>%A%T: <span class="entryText">%e</span></p>
If you want a really simple entry template, with no permalink, author, title, or anchor, try this:
<p>%d: %e</p>
The title template is a sub-template of the entry template. It's displayed for an entry only if that entry has a title and the entry template contains the %T directive.
This template recognizes the following special directive:
The default title template is as follows:
<span class="entryTitle">%t</span>
The author template is a sub-template of the entry template. It's displayed for an entry only if that entry has a title and the entry template contains the %A directive.
This template recognizes the following special directive:
The default author template is as follows:
(<span class="entryAuthor">%a</span>)
The title template is a sub-template of the entry template. It's displayed for an entry when the following conditions are met: the entry template contains the %e directive to print out the entry text, the entry text is longer than one paragraph, and the notebook has been configured to summarize long entries.
This template recognizes no special directives.
The default summary template is as follows:
%s [<a href="%v">More]
This template, and its sibling the category list detail template, are sub-templates of the entry template. The category list template is displayed for an entry when the entry belongs to one or more categories, and when the entry template contains the %categories directive. The category list detail template is displayed under the same circumstances in detail view.
This template recognizes the following special directives:
This template is a sub-template of the category list and category list detail templates. It is interpolated once for every category to which an entry belongs, when the %categories directive is found in its parent template.
This template recognizes the following special directives:
The default category template is as follows:
%category-commaIfNotFirst %category-linkedName
If you want to do a fancier category list, here's one suggestion. Set your category list template to this:
<div class="entryCategories">Filed under %category-numberOfCategories categor%category-plural: <ol>%category-each</ol></div>
And set your category template to this:
<li>%cn <span class="categoryDescription">%category-description</span></li>
The incoming trackback list and incoming trackback detail list are for printing out a list of an entry's incoming trackbacks. They are interpolated when the entry template or entry detail template contains the %trackbacks directive.
This template, and the templates it interpolates, recognize the following special directives:
This template recognizes the following special directives:
This template recognizes the following special directives.