346 MGraphics.ru - SSI - Функция IF
Уроки photoshopa


SSI

Функция IF

Условия перепечатки материалов

Рейтинг статьи: 11111
Проголосовал 1 человек.
Оцените статью:

if

The if tag provides for conditional execution of SSI operations, and conditional printing of HTML text, based on logical comparisons. The format of the if tag is :

'if' '"'<operand1>'"' <operator> '"'<operand2>'"'<operation>

where:

  • <operand1> is the first operand of a logical comparison statement
  • <operand2> is the second operand of a logical comparison statement
  • <operator> is the logical comparison method ['==', '!=','<', '>', '!<', '!>']
  • <operation> is the action to take if the logical comparison evaluates to TRUE ['goto', 'print', 'error', 'break', 'errorbreak', 'printbreak']

The operands may be any string or number (integer or floating point). In the event that both operands are numbers the comparison will be based on the value of the numbers. In the event that one or both of the operands and not numbers, the comparison will be based on the alphabetic order of the operands.

The special case of the NULL operand is defined by two quotes with no characters between them. The NULL operand may used to check for the existence of form data from the remote client (see example below).

  • The operator defines what kind of comparison is performed on the operands:
  • '==' The equalto operator evaluates to TRUE if the operands are equal to each other.
  • '!=' The notequalto operator evaluates to TRUE if the operands are not equal to each other.
  • '<' The lessthan operator evaluates to TRUE if operand1 is less than operand2.
  • '>' The greaterthan operator evaluates to TRUE if operand1 is greater than operand2
  • '!<' The notlessthan operator evaluates to TRUE if operand1 is not less than operand2
  • '!>' The notgreaterthan operator evaluates to TRUE if operand1 is not greater than operand2
  • 'hasstring' The hasstring operator returns TRUE is the text string in operand2 is found in the operand1 string.

In the event that the logical comparison evaluates to FALSE, nothing happens, If the logical comparison evaluates to TRUE then one of the following operations may be performed:

  • 'goto' causes a jump to a label token (see below).The format of the goto tag is:
    • 'goto' <label>
    • where <label> is the name of a label defined in a subsequent label tag (see below).
  • 'print' causes text to be printed. The format of the print tag is:
    • 'print' <text>
    • where <text> is any HTML text or tag.
  • 'error' causes the current config..error message to be printed.
  • 'break' causes termination of the HTML document transmission to the client.
  • 'errorbreak' causes the current config..error message to be printed, and then causes termination of the HTML document transmission to the client.
  • 'printbreak' causes text to be printed, and then causes termination of the HTML document transmission to the client. The format of the printbreak tag is the same as the format of the print tag.

Example. The following document fragment compares two numbers, if the operands are not equal then a goto will jump to a label.

  • <!--#if "10" != "20" goto testlabel-->
  • <P>This should not print
  • <!--#label ="testlabel" -->
  • <P>This should print

Example. The following document fragment demonstrates conditional execution based on data delivered from an HTML form. Suppose we have two form datum called 'formdata1' and 'formdata2' and we wish to compare them. The following document fragment compares the two operands, if the operands are equal then a goto will jump to a label. Otherwise the next line will print and the document will terminate on a break token (see below).

  • <!--#if "&&formdata1&&" == "&&formdata2&&" goto testlabel -->
  • <P>The operands are not equal.
  • <!--#break -->
  • <!--#label ="testlabel" -->
  • <P>operands are equal.

Example. The following document fragment prints two different statements depending on whether or not the client agent is NCSA Mosaic.

  • <!--#if "&&HTTP_USER_AGENT&&" hasstring "Mosaic" goto mosaiclabel -->
  • <P>You are not using Mosaic
  • <!--#goto ="defaultlabel" -->
  • <!--#label ="mosaiclabel" -->
  • <P>You are using Mosaic
  • <!--#label ="defaultlabel" -->

Example. Suppose we have a form with amongst other things a field named "BOO" and we wish to make sure that the remote client user enterted data into the "BOO" field before submitting the form. The following document fragment checks for the presence of data in the "BOO" field, if data exists then nothing happens, if data does not exist then a message will be displayed and the document will terminate.

  • <!--#if "&&BOO&&" == "" printbreak "<P>You must provide data for the BOO field, please resubmit." -->

Разместил: Vulko
Опубликовано: 21.06.2004
Статья "SSI - Функция IF" прочтена 8508 раз.





Последние новости