[ic] Did you know about [output] and [unpack]? (Part of a series)

Mike Heins mike at perusion.com
Sat May 28 13:45:03 EDT 2005

  Interchange can simply read an HTML page and output it to the HTTP
  server. Without ITL tag substitution, though, you might as well just use
  an HTTP server.

  In the simplest form, an ITL page is an HTML page with a few ITL tags in
  it. The following is an example:

     <head><title>A page</title></head>

      [if value fname]
          I recognize you! Hi, [value fname].
          Welcome, stranger.

        Some static page content.


  This is difficult to deal with on a large scale, though. Were the page
  to get more complex with complicated style, you would not want to have
  to rewrite and maintain sections of each page that are identical.

  In practice, most HTML pages have a content area that changes, and that
  would be contained within some wrapping HTML. To simplify this wrapping,
  Interchange uses a TOP and BOTTOM templating approach.

  Therefore, an Interchange page as shown in the demos takes the form:

     [set page_title]A page[/set]


      Some page content. 
      [if value fname]
          I recognize you! Hi, [value fname].
          Welcome, stranger.


  The "@_NOLEFT_TOP_@" is an Interchange Variable which can contain some
  common elements for a page. By naming convention, this page would be
  called the "noleft" template.

  The [set page_title] ... [/set] sets an Interchange scratch variable so
  that it can be referenced later in the page.

About Variable Replacement
  Variable substitution is a simple and often used feature of Interchange
  templates. It allows you to set a variable to a particular value set up
  in a database or configuration files. Then, by placing that variable
  name on a page, you invoke that value to be used. Before anything else
  is done on a template, all variable tokens are replaced by variable
  values. There are three types of variable tokens:

  __VARIABLENAME__ is replaced by the catalog variable called

  @@VARIABLENAME@@ is replaced by the global variable called VARIABLENAME.

  @_VARIABLENAME_@ is replaced by the catalog variable VARIABLENAME if it
  exists; otherwise, it is replaced by the global variable VARIABLENAME.

  In Interchange page templates, these variable values are used to hold
  the relatively-unchanging parts of the page -- i.e. the template.

Page flow
  In the latest version of Interchange, 5.3.1 as of this writing, there is
  this flow for an interchange page.

  1.  Page is read as a result of a request.

  2.  Variable substitution is done.

  3.  Page is parsed by the Interchange page interpolation routines. The
      "[output ..]" tag sends page output to arbitrary buffers.

  4.  Page output is remapped to a template -- usually located in
      include/layout -- and sent to the HTTP server.

  The [output ..] tag allows you to set a page region out of sequence. If
  output is always sequential, you must obviously set the page title
  before you output the <head> region of your page. Using Interchange's
  [output] allows you to set the title any time before the final unpacking
  of the layout.

The [output] and [unpack] tags
  The [output] tag routes all subsequent output to a named region, until
  such time as you change that with another [output] tag.

  Here is a small example of how to create a page using this approach.

     [output name=foo]
       Send this to the foo output.

     [output name="footer"]
       Send this to the footer output.

     [output name="title"]
       Send this to the title output.
     [output name="bar"]
       Send this to the bar output.

     [output name=""]
       Revert to the default output.

  The unnamed output area is the default output, and is selected to begin

  To unpack output from the buffers, you use the unpack tag:


      <div style="border: 1px solid black">


      <div style="border: 1px solid black">


  Note the {{SECTION}} markers. These are used by the [unpack] tag to find
  where to place the output from the various sections. (It should be
  obvious that {{FOO}} will receive the output of the [output name=foo],
  but sometimes we should actually confirm the obvious.)

  Interchange 5.x can be powerfully used as a templating system for
  managing content. Once you have templates properly set up, maintaining
  pages is pretty easy.

  Learn to use the [output ...] tag and the [unpack ..] templating
  approach, and it can simplify quite a few things.

Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.647.1295  tollfree 800-949-1889 <mike at perusion.com>

"Even if you're on the right track, you'll get run over if you just
sit there." -- Will Rogers

More information about the interchange-users mailing list