html(3tcl) 1.5 html "HTML Generation"

Name

html - Procedures to generate HTML structures

Table Of Contents

Synopsis

  • package require Tcl 8.2
  • package require html ?1.5?

Description

The package html provides commands that generate HTML. These commands typically return an HTML string as their result. In particular, they do not output their result to stdout.

The command ::html::init should be called early to initialize the module. You can also use this procedure to define default values for HTML tag parameters.

::html::author author

Side effect only. Call this before ::html::head to define an author for the page. The author is noted in a comment in the HEAD section.

::html::bodyTag args

Generate a body tag. The tag parameters are taken from args or from the body.* attributes define with ::html::init.

::html::cell param value ?tag?

Generate a td (or th) tag, a value, and a closing td (or th) tag. The tag parameters come from param or TD.* attributes defined with ::html::init. This uses ::html::font to insert a standard font tag into the table cell. The tag argument defaults to "td".

::html::checkbox name value

Generate a checkbox form element with the specified name and value. This uses ::html::checkValue.

::html::checkSet key sep list

Generate a set of checkbox form elements and associated labels. The list should contain an alternating list of labels and values. This uses ::html::checkbox. All the checkbox buttons share the same key for their name. The sep is text used to separate the elements.

::html::checkValue name ?value?

Generate the "name=name value=value" for a checkbox form element. If the CGI variable name has the value value, then SELECTED is added to the return value. value defaults to "1".

::html::closeTag

Pop a tag off the stack created by ::html::openTag and generate the corresponding close tag (e.g., </body>).

::html::default key ?param?

This procedure is used by ::html::tagParam to generate the name, value list of parameters for a tag. The ::html::default procedure is used to generate default values for those items not already in param. If the value identified by key matches a value in param then this procedure returns the empty string. Otherwise, it returns a "parameter=value" string for a form element identified by key. The key has the form "tag.parameter" (e.g., body.bgcolor). Use ::html::init to register default values. param defaults to the empty string.

::html::description description

Side effect only. Call this before ::html::head to define a description meta tag for the page. This tag is generated later in the call to ::html::head.

::html::end

Pop all open tags from the stack and generate the corresponding close HTML tags, (e.g., </body></html>).

::html::eval arg ?args?

This procedure is similar to the built-in Tcl eval command. The only difference is that it returns "" so it can be called from an HTML template file without appending unwanted results.

::html::extractParam param key ?varName?

This is a parsing procedure that extracts the value of key from param, which is a HTML-style "name=quotedvalue" list. varName is used as the name of a Tcl variable that is changed to have the value found in the parameters. The function returns 1 if the parameter was found in param, otherwise it returns 0. If the varName is not specified, then key is used as the variable name.

::html::font args

Generate a standard font tag. The parameters to the tag are taken from args and the HTML defaults defined with ::html::init.

::html::for start test next body

This procedure is similar to the built-in Tcl for control structure. Rather than evaluating the body, it returns the subst'ed body. Each iteration of the loop causes another string to be concatenated to the result value.

::html::foreach varlist1 list1 ?varlist2 list2 ...? body

This procedure is similar to the built-in Tcl foreach control structure. Rather than evaluating the body, it returns the subst'ed body. Each iteration of the loop causes another string to be concatenated to the result value.

::html::formValue name ?defvalue?

Return a name and value pair, where the value is initialized from existing CGI data, if any. The result has this form:

  name="fred" value="freds value"
::html::getFormInfo args

Generate hidden fields to capture form values. If args is empty, then hidden fields are generated for all CGI values. Otherwise args is a list of string match patterns for form element names.

::html::getTitle

Return the title string, with out the surrounding title tag, set with a previous call to ::html::title.

::html::h level string ?param?

Generate a heading (e.g., hlevel) tag. The string is nested in the heading, and param is used for the tag parameters.

::html::h1 string ?param?

Generate an h1 tag. See ::html::h.

::html::h2 stri