[ Previous ] [ Contents ] [ Index ] [ Next ]

Server-Parsed HTML Tags

Commands for the server to parse are stored as comments in the body of the HTML page. If the server cannot parse the file (for example, if the execute permission is not set) it returns the unparsed HTML to the browser.

The commands have this format:

    
    <!--#command arg="value" -->

Each command accepts different arguments. For example, this command includes a separate file within the page:

    
    <!--#include virtual="../includes/header.txt" -->

Only the #config command allows you to specify more than one argument (separated by spaces) on the line.

Here is a list of the commands you can use and their arguments:

#config

The #config command controls how the file is parsed. These are the arguments it accepts:

Examples: <!--#config errmsg="File could not be parsed" -->

    		<!--#config sizefmt="bytes" timefmt="%A %b %d"-->

#echo

The #echo command includes the value of one of the environment variables defined for CGI programs (see Standard Environment Variables) or one of the special variables listed on Special Variables. The only argument is "var", whose value is the name of the variable you want to output.

Example: <!--#echo var="HTTP_USER_AGENT" -->

#exec

The #exec command runs a shell command or CGI program. The valid arguments are:

Note: You can disable the #exec command by using the NoExec option in the Map parameter in the server setup pages. You may want to disable this command for security reasons.

Examples: <!--#exec cmd="ls -ltr" -->

<!--#exec cgi="cgi-bin/fill_in" -->

#include

The #include command inserts the contents of the file you specify at the location of the #include command. The user must have read access to the file that gets included. If the file that is included has a file extension or location that causes it to be parsed by the server, that file can in turn include other files.

Make sure files you include contain only tags that are appropriate in the context of the files that include them. For example, don't use the <HTML>, <HEAD>, or <BODY> tags (or their end tags) in a file that will be included in another file that already contains these tags.

The #include command accepts either of the following arguments:

One difference between these two arguments is that "file" uses the physical file structure on the server machine, while "virtual" uses the structure seen from the outside by those accessing the server.

Examples: <!--#include file="include.txt" -->

<!--#include virtual="/doc/cust/include.txt" -->

#flastmod

The #flastmod command prints the last modification date of the file you specify. It uses the format specified with the timefmt argument to the #config command. The valid arguments are virtual and file, which have the same functions as they do for the #include command.

Example: <!--#flastmod file="/sub/myfile.html" -->

#fsize

The #fsize command prints the size of the file you specify. It uses the format specified with the sizefmt argument to the #config command. The valid arguments are virtual and file, which have the same functions as they do for the #include command.

Example: <!--#fsize virtual="/sales/sub/myfile.html" -->

#nstcl

The #nstcl command executes a Tcl script. Its only argument is script, whose value is the Tcl function, along with its corresponding arguments, that you want to execute. For example, you can execute a one-line script in an HTML page as follows:

    <!--#nstcl script="ns_info build" -->

Here is a more complex example of a script to be executed in an HTML page. This Tcl script queries the database and returns an HTML unnumbered list of the results:

    <HTML>
    <HEAD>
    <TITLE>All Employees</TITLE>
    </HEAD>
    <BODY>
    <H1>All Employees</H1>
    <!--#nstcl script="
    # This example queries a database in the default
    # pool and returns a list of all the employees listed
    # in the employees table.  It assumes a table called
    # employees exists with the column emp_name. You can 
    # use the /NS/Db/Admin to create the table.
    #
    # Note: You must have database services activated in your
    #       virtual server for this example to work.
    set ul {<UL>}
    set db [ns_db gethandle]
    set row [ns_db select $db \
            {select emp_name from employees order by 
emp_name;}]
    while { [ns_db getrow $db $row] } {
         append ul <LI>[ns_set get $row emp_name]\n
    }
    append ul {</UL>}
    set ul" -->
    </BODY>
    </HTML>

Note that since the entire Tcl script must be surrounded with double quotes ("), you cannot use any double quotes in the script itself.

Note that if the "NoExec" option is set in the Map parameter, the #nstcl command is disabled.

Date and Time Formats

This table shows some of the formats you can use to create the date/time format for the timefmt argument to the #config command. (See the strftime UNIX man page for more details.) In addition, you can use any punctuation in the formatting string, including %t for a tab and %n for a line break.
Format Description Example
%a Abbreviated weekday name Wed
%A Full weekday name Thursday
%b Abbreviated month name Mar
%B Full month name April
%c Default short date/time format
%C Default long date/time format
%d Day of month; Single digits preceded by 0 09
%e Day of month; single digits preceded by a space 9
%H Hour (24-hour clock); single digits preceded by 0 23
%I Hour (12-hour clock); single digits preceded by 0 12
%j Day number of year; single digits preceded by 0 325
%k Hour (24-hour clock); single digits preceded by a blank 8
%l Hour (12-hour clock); single digits preceded by a blank 12
%m Month number; single digits preceded by a blank 10
%M Minute; leading zero is permitted but not required 30
%p Either a.m. or p.m. AM
%r Time in 12-hour clock format with %p 11:12:45 AM
%S Seconds 42
%U Week number of year; Sunday is first day of week 1 51
%w Weekday number, with 0 representing Sunday 0
%x Default short date format
%X Default time format
%y Two-digit year within century 96
%Y Four-digit year 1996
%Z Time zone name or abbreviation (blank if not available) PST

Top of Page

[ Previous ] [ Contents ] [ Index ] [ Next ]
Copyright © 1996 America Online, Inc.