1[comment {-*- tcl -*- doctools manpage}] 2[vset HTML_VERSION 1.5] 3[manpage_begin html n [vset HTML_VERSION]] 4[see_also htmlparse] 5[see_also ncgi] 6[keywords checkbox] 7[keywords checkbutton] 8[keywords form] 9[keywords html] 10[keywords radiobutton] 11[keywords table] 12[moddesc {HTML Generation}] 13[titledesc {Procedures to generate HTML structures}] 14[category {CGI programming}] 15[require Tcl 8.2] 16[require html [opt [vset HTML_VERSION]]] 17[description] 18[para] 19 20The package [package html] provides commands that generate HTML. 21These commands typically return an HTML string as their result. In 22particular, they do not output their result to [const stdout]. 23 24[para] 25 26The command [cmd ::html::init] should be called early to initialize 27the module. You can also use this procedure to define default values 28for HTML tag parameters. 29 30[list_begin definitions] 31 32[call [cmd ::html::author] [arg author]] 33 34[emph {Side effect only}]. Call this before [cmd ::html::head] to 35define an author for the page. The author is noted in a comment in 36the HEAD section. 37 38[call [cmd ::html::bodyTag] [arg args]] 39 40Generate a [term body] tag. The tag parameters are taken from [arg args] or 41from the body.* attributes define with [cmd ::html::init]. 42 43[call [cmd ::html::cell] [arg {param value}] [opt [arg tag]]] 44 45Generate a [term td] (or [term th]) tag, a value, and a closing 46[term td] (or [term th]) tag. The 47tag parameters come from [arg param] or TD.* attributes defined with 48[cmd ::html::init]. This uses [cmd ::html::font] to insert a standard 49[term font] tag into the table cell. The [arg tag] argument defaults to "td". 50 51[call [cmd ::html::checkbox] [arg {name value}]] 52 53Generate a [term checkbox] form element with the specified name and value. 54This uses [cmd ::html::checkValue]. 55 56[call [cmd ::html::checkSet] [arg {key sep list}]] 57 58Generate a set of [term checkbox] form elements and associated labels. The 59[arg list] should contain an alternating list of labels and values. 60This uses [cmd ::html::checkbox]. All the [term checkbox] buttons share the 61same [arg key] for their name. The [arg sep] is text used to separate 62the elements. 63 64[call [cmd ::html::checkValue] [arg name] [opt [arg value]]] 65 66Generate the "name=[arg name] value=[arg value]" for a [term checkbox] form 67element. If the CGI variable [arg name] has the value [arg value], 68then SELECTED is added to the return value. [arg value] defaults to 69"1". 70 71[call [cmd ::html::closeTag]] 72 73Pop a tag off the stack created by [cmd ::html::openTag] and generate 74the corresponding close tag (e.g., </body>). 75 76[call [cmd ::html::default] [arg key] [opt [arg param]]] 77 78This procedure is used by [cmd ::html::tagParam] to generate the name, 79value list of parameters for a tag. The [cmd ::html::default] 80procedure is used to generate default values for those items not 81already in [arg param]. If the value identified by [arg key] matches 82a value in [arg param] then this procedure returns the empty string. 83Otherwise, it returns a "parameter=value" string for a form element 84identified by [arg key]. The [arg key] has the form "tag.parameter" 85(e.g., body.bgcolor). Use [cmd ::html::init] to register default 86values. [arg param] defaults to the empty string. 87 88[call [cmd ::html::description] [arg description]] 89 90[emph {Side effect only}]. Call this before [cmd ::html::head] to 91define a description [term meta] tag for the page. This tag is generated 92later in the call to [cmd ::html::head]. 93 94[call [cmd ::html::end]] 95 96Pop all open tags from the stack and generate the corresponding close 97HTML tags, (e.g., </body></html>). 98 99[call [cmd ::html::eval] [arg arg] [opt [arg args]]] 100 101This procedure is similar to the built-in Tcl [cmd eval] command. The 102only difference is that it returns "" so it can be called from an HTML 103template file without appending unwanted results. 104 105[call [cmd ::html::extractParam] [arg {param key}] [opt [arg varName]]] 106 107This is a parsing procedure that extracts the value of [arg key] from 108[arg param], which is a HTML-style "name=quotedvalue" list. 109 110[arg varName] is used as the name of a Tcl variable that is changed to 111have the value found in the parameters. The function returns 1 if the 112parameter was found in [arg param], otherwise it returns 0. If the 113[arg varName] is not specified, then [arg key] is used as the variable 114name. 115 116[call [cmd ::html::font] [arg args]] 117 118Generate a standard [term font] tag. The parameters to the tag are taken 119from [arg args] and the HTML defaults defined with [cmd ::html::init]. 120 121[call [cmd ::html::for] [arg {start test next body}]] 122 123This procedure is similar to the built-in Tcl [cmd for] control 124structure. Rather than evaluating the body, it returns the subst'ed 125[arg body]. Each iteration of the loop causes another string to be 126concatenated to the result value. 127 128[call [cmd ::html::foreach] [arg {varlist1 list1}] [opt [arg {varlist2 list2 ...}]] [arg body]] 129 130This procedure is similar to the built-in Tcl [cmd foreach] control 131structure. Rather than evaluating the body, it returns the subst'ed 132[arg body]. Each iteration of the loop causes another string to be 133concatenated to the result value. 134 135[call [cmd ::html::formValue] [arg name] [opt [arg defvalue]]] 136 137Return a name and value pair, where the value is initialized from 138existing CGI data, if any. The result has this form: 139 140[para] 141[example { 142 name="fred" value="freds value" 143}] 144 145[call [cmd ::html::getFormInfo] [arg args]] 146 147Generate hidden fields to capture form values. If [arg args] is 148empty, then hidden fields are generated for all CGI values. Otherwise 149args is a list of string match patterns for form element names. 150 151[call [cmd ::html::getTitle]] 152 153Return the title string, with out the surrounding [term title] tag, 154set with a previous call to [cmd ::html::title]. 155 156[call [cmd ::html::h] [arg {level string}] [opt [arg param]]] 157 158Generate a heading (e.g., [term h[var level]]) tag. The [arg string] is nested in the 159heading, and [arg param] is used for the tag parameters. 160 161[call [cmd ::html::h1] [arg string] [opt [arg param]]] 162 163Generate an [term h1] tag. See [cmd ::html::h]. 164 165[call [cmd ::html::h2] [arg string] [opt [arg param]]] 166 167Generate an [term h2] tag. See [cmd ::html::h]. 168 169[call [cmd ::html::h3] [arg string] [opt [arg param]]] 170 171Generate an [term h3] tag. See [cmd ::html::h]. 172 173[call [cmd ::html::h4] [arg string] [opt [arg param]]] 174 175Generate an [term h4] tag. See [cmd ::html::h]. 176 177[call [cmd ::html::h5] [arg string] [opt [arg param]]] 178 179Generate an [term h5] tag. See [cmd ::html::h]. 180 181[call [cmd ::html::h6] [arg string] [opt [arg param]]] 182 183Generate an [term h6] tag. See [cmd ::html::h]. 184 185[call [cmd ::html::hdrRow] [arg args]] 186 187Generate a table row, including [term tr] and [term th] tags. 188Each value in [arg args] is place into its own table cell. 189This uses [cmd ::html::cell]. 190 191[call [cmd ::html::head] [arg title]] 192 193Generate the [term head] section that includes the page [term title]. 194If previous calls have been made to 195[cmd ::html::author], 196[cmd ::html::keywords], 197[cmd ::html::description], 198or 199[cmd ::html::meta] 200then additional tags are inserted into the [term head] section. 201This leaves an open [term html] tag pushed on the stack with 202[cmd ::html::openTag]. 203 204[call [cmd ::html::headTag] [arg string]] 205 206Save a tag for inclusion in the [term head] section generated by 207 208[cmd ::html::head]. The [arg string] is everything in the tag except 209the enclosing angle brackets, < >. 210 211[call [cmd ::html::html_entities] [arg string]] 212 213This command replaces all special characters in the [arg string] with 214their HTML entities and returns the modified text. 215 216[call [cmd ::html::if] [arg {expr1 body1}] [opt "[const elseif] [arg {expr2 body2 ...}]"] [opt "[const else] [arg bodyN]"]] 217 218This procedure is similar to the built-in Tcl [cmd if] control 219structure. Rather than evaluating the body of the branch that is 220taken, it returns the subst'ed [arg body]. Note that the syntax is 221slightly more restrictive than that of the built-in Tcl [cmd if] 222control structure. 223 224[call [cmd ::html::init] [opt [arg list]]] 225 226[cmd ::html::init] accepts a Tcl-style name-value list that defines 227values for items with a name of the form "tag.parameter". For 228example, a default with key "body.bgcolor" defines the background 229color for the [term body] tag. 230 231[call [cmd ::html::keywords] [arg args]] 232 233[emph {Side effect only}]. Call this before [cmd ::html::head] to 234define a keyword [term meta] tag for the page. The [term meta] tag 235is included in the result of [cmd ::html::head]. 236 237[call [cmd ::html::mailto] [arg email] [opt [arg subject]]] 238 239Generate a hypertext link to a mailto: URL. 240 241[call [cmd ::html::meta] [arg args]] 242 243Compatibility name for [cmd html::meta_name]. 244 245[call [cmd ::html::meta_name] [arg args]] 246 247[emph {Side effect only}]. 248 249Call this before [cmd ::html::head] to define a [term meta] tag for 250the page. 251 252The arguments ([arg args]) are a Tcl-style name, value list that is 253used for the [const name=] and [const content=] attributes of the 254[term meta] tag. The [term meta] tag is included in the result of 255[cmd ::html::head]. 256 257 258[call [cmd ::html::meta_equiv] [arg args]] 259 260[emph {Side effect only}]. 261 262Call this before [cmd ::html::head] to define a [term meta] tag for 263the page. 264 265The arguments ([arg args]) are a Tcl-style name, value list that is 266used for the [const http-equiv=] and [const content=] attributes of 267the [term meta] tag. The [term meta] tag is included in the result of 268[cmd ::html::head]. 269 270[call [cmd ::html::meta_charset] [arg charset]] 271 272[emph {Side effect only}]. 273 274Call this before [cmd ::html::head] to 275define a [term meta] tag for the page. 276 277The [arg charset] is used with the [const charset=] attribute of the 278[term meta] tag. The [term meta] tag is included in the result of 279[cmd ::html::head]. 280 281[call [cmd ::html::css] [arg href]] 282 283[emph {Side effect only}]. Call this before [cmd ::html::head] to 284define a [term link] tag for a linked CSS document. The [arg href] 285value is a HTTP URL to a CSS document. The [term link] tag is included 286in the result of [cmd ::html::head]. 287 288[para] 289 290Multiple calls of this command are allowed, enabling the use of 291multiple CSS document references. In other words, the arguments 292of multiple calls are accumulated, and do not overwrite each other. 293 294[call [cmd ::html::css-clear]] 295 296[emph {Side effect only}]. Call this before [cmd ::html::head] to 297clear all links to CSS documents. 298[para] 299 300Multiple calls of this command are allowed, doing nothing after the 301first of a sequence with no intervening [cmd ::html::css]. 302 303[call [cmd ::html::js] [arg href]] 304 305[emph {Side effect only}]. Call this before [cmd ::html::head] to 306define a [term script] tag for a linked JavaScript document. The 307[arg href] is a HTTP URL to a JavaScript document. The [term script] 308tag is included in the result of [cmd ::html::head]. 309 310[para] 311 312Multiple calls of this command are allowed, enabling the use of 313multiple JavaScript document references. In other words, the arguments 314of multiple calls are accumulated, and do not overwrite each other. 315 316 317[call [cmd ::html::js-clear]] 318 319[emph {Side effect only}]. Call this before [cmd ::html::head] to 320clear all links to JavaScript documents. 321[para] 322 323Multiple calls of this command are allowed, doing nothing after the 324first of a sequence with no intervening [cmd ::html::js]. 325 326[call [cmd ::html::minorList] [arg list] [opt [arg ordered]]] 327 328Generate an ordered or unordered list of links. The [arg list] is a 329Tcl-style name, value list of labels and urls for the links. 330 331[arg ordered] is a boolean used to choose between an ordered or 332unordered list. It defaults to [const false]. 333 334[call [cmd ::html::minorMenu] [arg list] [opt [arg sep]]] 335 336Generate a series of hypertext links. The [arg list] is a Tcl-style 337name, value list of labels and urls for the links. The [arg sep] is 338the text to put between each link. It defaults to " | ". 339 340[call [cmd ::html::nl2br] [arg string]] 341 342This command replaces all line-endings in the [arg string] with a 343[term br] tag and returns the modified text. 344 345[call [cmd ::html::openTag] [arg tag] [opt [arg param]]] 346 347Push [arg tag] onto a stack and generate the opening tag for 348[arg tag]. Use [cmd ::html::closeTag] to pop the tag from the 349stack. The second argument provides any tag arguments, as a 350list whose elements are formatted to be in the form 351"[var key]=[const value]". 352 353[call [cmd ::html::paramRow] [arg list] [opt [arg rparam]] [opt [arg cparam]]] 354 355Generate a table row, including [term tr] and [term td] tags. Each value in 356 357[arg list] is placed into its own table cell. This uses 358 359[cmd ::html::cell]. The value of [arg rparam] is used as parameter for 360the [term tr] tag. The value of [arg cparam] is passed to [cmd ::html::cell] 361as parameter for the [term td] tags. 362 363[call [cmd ::html::passwordInput] [opt [arg name]]] 364 365Generate an [term input] tag of type [term password]. The [arg name] defaults to 366"password". 367 368[call [cmd ::html::passwordInputRow] [arg label] [opt [arg name]]] 369 370Format a table row containing a label and an [term input] tag of type 371[term password]. The [arg name] defaults to "password". 372 373[call [cmd ::html::quoteFormValue] [arg value]] 374 375Quote special characters in [arg value] by replacing them with HTML 376entities for quotes, ampersand, and angle brackets. 377 378[call [cmd ::html::radioSet] [arg {key sep list}]] 379 380Generate a set of [term input] tags of type [term radio] and an associated text 381label. All the radio buttons share the same [arg key] for their name. 382The [arg sep] is text used to separate the elements. The [arg list] 383is a Tcl-style label, value list. 384 385[call [cmd ::html::radioValue] [arg {name value}]] 386 387Generate the "name=[arg name] value=[arg value]" for a [term radio] form 388element. If the CGI variable [arg name] has the value [arg value], 389then SELECTED is added to the return value. 390 391[call [cmd ::html::refresh] [arg {seconds url}]] 392 393Set up a refresh [term meta] tag. Call this before [cmd ::html::head] and the 394HEAD section will contain a [term meta] tag that causes the document to 395refresh in [arg seconds] seconds. The [arg url] is optional. If 396specified, it specifies a new page to load after the refresh interval. 397 398[call [cmd ::html::row] [arg args]] 399 400Generate a table row, including [term tr] and [term td] tags. Each value in 401[arg args] is place into its own table cell. This uses 402[cmd ::html::cell]. Ignores any default information set up via 403[cmd ::html::init]. 404 405[call [cmd ::html::select] [arg {name param choices}] [opt [arg current]]] 406 407Generate a [term select] form element and nested [term option] tags. The [arg name] 408and [arg param] are used to generate the [term select] tag. The [arg choices] 409list is a Tcl-style name, value list. 410 411[call [cmd ::html::selectPlain] [arg {name param choices}] [opt [arg current]]] 412 413Like [cmd ::html::select] except that [arg choices] is a Tcl list of 414values used for the [term option] tags. The label and the value for each 415[term option] are the same. 416 417[call [cmd ::html::set] [arg {var val}]] 418 419This procedure is similar to the built-in Tcl [cmd set] command. The 420main difference is that it returns "" so it can be called from an HTML 421template file without appending unwanted results. The other 422difference is that it must take two arguments. 423 424[call [cmd ::html::submit] [arg label] [opt [arg name]] [opt [arg title]]] 425 426Generate an [term input] tag of type [term submit]. 427 428The [arg name] defaults to "submit". 429 430When a non-empty [arg title] string is specified the button gains a 431[const title=] attribute with that value. 432 433[call [cmd ::html::tableFromArray] [arg arrname] [opt [arg param]] [opt [arg pat]]] 434 435Generate a two-column [term table] and nested rows to display a Tcl array. The 436table gets a heading that matches the array name, and each generated row 437contains a name, value pair. The array names are sorted ([cmd lsort] without 438special options). The argument [arg param] is for the [term table] tag and has 439to contain a pre-formatted string. The [arg pat] is a [cmd {string match}] 440pattern used to select the array elements to show in the table. It defaults to 441[const *], i.e. the whole array is shown. 442 443[call [cmd ::html::tableFromList] [arg querylist] [opt [arg param]]] 444 445Generate a two-column [term table] and nested rows to display [arg querylist], 446which is a Tcl dictionary. Each generated row contains a name, value pair. The 447information is shown in the same order as specified in the dictionary. The 448argument [arg param] is for the [term table] tag and has to contain a 449pre-formatted string. 450 451[call [cmd ::html::textarea] [arg name] [opt [arg param]] [opt [arg current]]] 452 453Generate a [term textarea] tag wrapped around its current values. 454 455[call [cmd ::html::textInput] [arg {name value args}]] 456 457Generate an [term input] form tag with type [term text]. This uses 458 459[cmd ::html::formValue]. The args is any additional tag attributes 460you want to put into the [term input] tag. 461 462[call [cmd ::html::textInputRow] [arg {label name value args}]] 463 464Generate an [term input] form tag with type [term text] formatted into a table row 465with an associated label. The args is any additional tag attributes 466you want to put into the [term input] tag. 467 468[comment { 469[call [cmd ::html::title] [arg title]] 470 471[emph {Side effect only}]. Call this before [cmd ::html::head] to 472define the [term title] for a page. 473}] 474 475[call [cmd ::html::varEmpty] [arg name]] 476 477This returns 1 if the named variable either does not exist or has the 478empty string for its value. 479 480[call [cmd ::html::while] [arg {test body}]] 481 482This procedure is similar to the built-in Tcl [cmd while] control 483structure. Rather than evaluating the body, it returns the subst'ed 484[arg body]. Each iteration of the loop causes another string to be 485concatenated to the result value. 486 487[call [cmd ::html::doctype] [arg id]] 488 489This procedure can be used to build the standard DOCTYPE 490declaration string. It will return the standard declaration 491string for the id, or throw an error if the id is not known. 492The following id's are defined: 493 494[list_begin enumerated] 495[enum] HTML32 496[enum] HTML40 497[enum] HTML40T 498[enum] HTML40F 499[enum] HTML401 500[enum] HTML401T 501[enum] HTML401F 502[enum] XHTML10S 503[enum] XHTML10T 504[enum] XHTML10F 505[enum] XHTML11 506[enum] XHTMLB 507[list_end] 508 509[call [cmd ::html::wrapTag] [arg tag] [opt [arg text]] [opt [arg args]]] 510 511A helper to wrap a [arg text] in a pair of open/close [arg tag]s. 512 513The arguments ([arg args]) are a Tcl-style name, value list that is 514used to provide attributes and associated values to the opening tag. 515 516The result is a string with the open [arg tag] along with the optional 517attributes, the optional text, and the closed tag. 518 519[list_end] 520 521[vset CATEGORY html] 522[include ../common-text/feedback.inc] 523[manpage_end] 524