4D v12.44D HTML Tags |
||||||||||||||||||||||||||||||
|
4D v12.4
4D HTML Tags
|
Sending Conditions | Content analysis of the sent pages |
Page extension (general case): | |
.htm, .html, .shtm, .shtml (HTML pages) | X |
.xml, .xsl (XML pages) | X |
.wml (WML pages) | X |
Pages called via URLs | X, except for pages with “.htm” or “.html” extensions |
SEND HTML FILE command call | X |
SEND HTML TEXT command call | X |
SEND HTML BLOB command call (if the BLOB is “text/html” type) | X |
Inclusion by the <!--4DINCLUDE --> tag | X |
In order to be processed by 4D, an HTML comment should have the following format <!--#4D...-->. Please note that some HTML editors automatically add other information within the comment; this can lead to some misinterpretation.
However, other HTML comments such as <!--Beginning of list--> are possible.
If a comment <!--#4D... does not end by -->, the following message “<!--#4D... : --> expected” will be inserted and the analysis will stop at this level (the page will be sent to indicate the error).
It is possible to mix several types of comments. For example, the following HTML syntax is possible:
<HTML> ... <BODY> <!--#4DSCRIPT/PRE_PROCESS--> (Method call) <!--#4DIF (myvar=1)--> (If condition) <!--#4DINCLUDE banner1.html--> (Subpage insertion) <!--#4DENDIF--> (End if) <!--#4DIF (myvar=2)--> <!--#4DINCLUDE banner2.html--> <!--#4DENDIF--> <!--#4DLOOP [TABLE]--> (loop on the current selection) <!--#4DIF ([TABLE]ValNum>10)--> (If [TABLE]ValNum>10) <!--#4DINCLUDE subpage.html--> (subpage insertion) <!--#4DELSE--> (Else) <B>Value: <!--#4DTEXT [TABLE]ValNum--></B><BR> (Field display) <!--#4DENDIF--> <!--#4DENDLOOP--> (End for) </BODY> </HTML>
Syntax: <!--#4DTEXT VarName--> or <!--#4DTEXT 4DExpression-->
The tag <!--#4DTEXT VarName--> allows you to insert a reference to the 4D variable or expression VarName anywhere in an HTML page. For example, if you write:
<P>Welcome to <!--#4DTEXT vtSiteName-->!</P>
The value of the 4D variable vtSiteName will be inserted in the HTML page when it is sent. This value is inserted as simple text.
You can also insert 4D expressions using the 4DTEXT tag. You can for example directly insert the contents of a field (<!--#4DTEXT [tableName]fieldName-->), an array element (<!--#4DTEXT tabarr1}-->) or a method returning a value (<!--#4DTEXT mymethod-->).
The expression conversion follows the same rules as the variable ones. Moreover, the expression must comply with 4D syntax rules.
Note: Executing a 4D method with 4DTEXT depends on the value of the “Available through 4D HTML tags and URLs (4DACTION...)” attribute set in the Method properties. For more information about this, refer to the Connection Security section.
Although an expression can contain direct calls to 4D functions, this is not recommended for localization issues. For example, <!--#4DTEXT Current date-->, although correctly interpreted with a 4D in English will not be understood by an French version. The same applies to real numbers (the decimal separator can be different according to the language). In both cases, we strongly advise you to assign a variable through programming.
In case of interpretation error, the inserted text will appear as “<!--#4DTEXT myvar--> : ## error # error code”.
Notes:
Compatibility note: This more specialized tag replaces the generic 4DVAR tag starting with version 12.2 of 4D. The 4DVAR tag is still supported and works as in previous versions. However, it is now recommended to use the 4DTEXT tag to insert text.
Syntax: <!--#4DHTML VarName--> or <!--#4DHTML 4DExpression-->
This tag lets you assess a variable or 4D expression and insert it into a page as an HTML expression. Unlike the 4DTEXT tag, this tag converts the characters to HTML code.
For example, here are the insertion results of the 4D text variable myvar with the available tags:
myvar Value | Tags | Web Page Insertion |
myvar:="<B>" | <!--#4DTEXT myvar--> | <B> |
myvar:="<B>" | <!--#4DHTML myvar--> | <B> |
In case of an interpretation error, the inserted text will be “<!--#4DHTML myvar--> : ## error # error code”.
Note: Executing a 4D method with 4DHTML depends on the value of the “Available through 4D HTML tags and URLs (4DACTION...)” attribute set in the Method properties. For more information about this, refer to the Connection Security section.
Note: The text variable should be expressed using the ISO Latin-1 character map (for more information, refer to the Mac to ISO command description).
Compatibility note: This tag replaces the 4DHTMLVAR tag starting with version 12.2 of 4D. The 4DHTMLVAR tag is still supported but for better code readability, it is now recommended to use the 4DHTML tag for inserting HTML code.
Syntax: <!--#4DSCRIPT/MethodName/MyParam-->
The 4DSCRIPT tag allows you to execute 4D methods when sending static HTML pages. The presence of the <!--#4DSCRIPT/MyMethod/MyParam--> tag in a static page as an HTML comment forces the execution of the MyMethod method with the MyParam parameter as a string in $1. When loading the home page, 4D calls the Database Engine Errors (-10600 -> 4004)On Web Authentication Database Method (if it exists). If it returns True, 4D executes the method.
The method returns text in $0. If the string starts with the code character 1, it is considered as HTML (the same principle is true for the variables).
Note: The execution of a method with 4DSCRIPT depends on the value of the “Available through 4D HTML tags and URLs (4DACTION...)” attribute defined in the Method properties. For more information about this, refer to the Connection Security section.
The analysis of the contents of the page is done when either SEND HTML FILE (.htm, .html, .shtm, .shtml) or SEND HTML BLOB (blob of type text/html) is called.
Remember that in non-contextual mode, the analysis is also done when a URL points to a file that has either the “.shtm” or “.shtml” extension (for example http://www.server.com/dir/page.shtm).
For example, let’s say that you insert the following comment “Today is <!--#4DSCRIPT/MYMETH/MYPARAM-->” into a static page. When loading the page, 4D calls the On Web Authentication Database Method (if it exists), then calls the MYMETH method and passes the string “/MYPARAM” as the parameter $1.
The method returns text in $0 (for example “12/31/10”); the expression “Today is <!--#4DSCRIPT/MYMETH/MYPARAM––>” therefore becomes “Today is 12/31/10”.
The MYMETH method is as follows:
C_TEXT($0)\\This parameter must always be declared
C_TEXT($1)\\This parameter must always be declared
$0:=String(Current date)
Warning: You must always declare the $0 and $1 parameters in the called method.
Note: A method called by 4DSCRIPT must not call interface elements (DIALOG, ALERT...).
As 4D executes methods in their order of appearance, it is absolutely possible to call a method that sets the value of many variables that are referenced further in the document, whichever mode you are using.
Note: You can insert as many <!--#4DSCRIPT...--> comments as you want in a static page.
Syntax: <!--#4DINCLUDE Path-->
This comment allows another HTML page (indicated by the path parameter) to be included in an HTML page. By default, only the body of the HTML page that is specified is included, in other words, the contents found within the <body> and </body> tags (the tags themselves are not included). This lets you avoid conflicts related to meta tags present in the headers. However, if the HTML page specified does not contain <body></body> tags, the entire page is included. It is up to you to verify the consistency of the meta tags.
The <!--#4DINCLUDE --> comment is very useful for tests (<!--#4DIF-->) or loops (<!--#4DLOOP-->). It is very convenient to include tags according to a criteria or randomly.
When including, regardless of the file name extension, 4D analyzes the called page and then inserts the contents (modified or not) in the page originating the 4DINCLUDE call.
An included page with the <!--#4DINCLUDE --> comment is loaded in the Web server cache the same way as pages called via a URL or sent with the SEND HTML FILE command.
In path, put the path leading to the document to include. Warning: In the case of a 4DINCLUDE call, the path is relative to the document being analyzed, that is, the “parent” document. Use the slash character (/) as a folder separator and the two dots (..) to go up one level (HTML syntax).
Note: When you use the 4DINCLUDE tag with the PROCESS HTML TAGS command, the default folder is the folder containing the database structure file.
The number of <!--#4DINCLUDE path--> within a page is unlimited. However, the <!--#4DINCLUDE path--> calls can be made only at one level. This means that, for example, you cannot insert <!--#4DINCLUDE mydoc3.html--> in the mydoc2.html body page, which is called by <!--#4DINCLUDE mydoc2--> inserted in mydoc1.html.
Furthermore, 4D verifies that inclusions are not recursive.
In case of error, the inserted text is "<!--#4DINCLUDE path--> :The document cannot be opened".
Examples
<!--#4DINCLUDE subpage.html--> <!--#4DINCLUDE folder/subpage.html--> <!--#4DINCLUDE ../folder/subpage.html-->
Syntax: <!--#4DIF expression--> <!--#4DELSE--> <!--#4DENDIF-->
Used with the <!--#4DELSE--> (optional) and <!--#4DENDIF--> comments, the <!--#4DIF expression--> comment offers the possibility to execute HTML code conditionally.
The expression parameter can contain any valid 4D expression returning a Boolean value. It must be indicated within parenthesis and comply with the 4D syntax rules.
The <!--#4DIF expression--> ... <!--#4DENDIF--> blocks can be nested in several levels. Like in 4D, each <!--#4DIF expression--> should match a <!--#4DENDIF-->.
In case of an interpretation error, the text “<!--#4DIF expression-->: A boolean expression was expected” is inserted instead of the contents located between <!--#4DIF --> and <!--#4DENDIF-->.
Likewise, if there are not as many <!--#4DENDIF--> as <!--#4DIF -->, the text “<!--#4DIF expression-->: 4DENDIF expected” is inserted instead of the contents located between <!--#4DIF --> and <!--#4DENDIF-->.
This example of code inserted in a static HTML page displays a different label according the vname#"" expression result:
<BODY> ... <!--#4DIF (vname#"")--> Names starting with <!--#4DTEXT vname-->. <!--#4DELSE--> No name has been found. <!--#4DENDIF--> ... </BODY>
Syntax: <!--#4DLOOP condition--> <!--#4DENDLOOP-->
This comment allows repetition of a portion of HTML code as long as the condition is fulfilled. The portion is delimited by <!--#4DLOOP--> and <!--#4DENDLOOP-->.
The <!--#4DLOOP condition--> ... <!--#4DENDLOOP--> blocks can be nested. Like in 4D, each <!--#4DLOOP condition--> should match a <!--#4DENDLOOP-->.
There are three kinds of conditions:
Note: When the 4DLOOP tag is used with a table, records are loaded in Read only mode.
The following HTML code:
<!--#4DLOOP [People]--> <!--#4DTEXT [People]Name--> <!--#4DTEXT [People]Surname--><BR> <!--#4DENDLOOP-->
... could be expressed in 4D language in the following way:
FIRST RECORD([People])
While(Not(End selection([People])))
...
NEXT RECORD([People])
End while
Note: This syntax cannot be used with two dimension arrays. In this case, it is better to combine a method with nested loops.
The following HTML code example:
<!--#4DLOOP arr_names--> <!--#4DTEXT arr_names{arr_names}--><BR> <!--#4DENDLOOP-->
... could be expressed in 4D language in the following way:
For($Elem;1;Size of array(arr_names))
arr_names:=$Elem
...
End for
For security reasons, the On Web Authentication Database Method can be called once just before the initialization stage (method execution with 0 as parameter). If the authentication is OK, the initialization stage will proceed.
Warning: C_BOOLEAN($0) and C_LONGINT($1) MUST be declared within the method for compilation purposes.
The following HTML code example:
<!--#4DLOOP my_method--> <!--#4DTEXT var--> <BR> <!--#4DENDLOOP-->
... could be expressed in 4D language in the following way:
If(AuthenticationWebOK)
If(my_method(0))
$counter:=1
While(my_method($counter))
...
$counter:=$counter+1
End while
End if
End if
The my_method method can be as follow:
C_LONGINT($1)
C_BOOLEAN($0)
If($1=0)
`Initialisation
$0:=True
Else
If($1<50)
...
var:=...
$0:=True
Else
$0:=False `Stops the loop
End if
End if
In case of an interpretation error, the text “<!--#4DLOOP expression-->: description” is inserted instead of the contents located between <!--#4DLOOP --> and <!--#4DENDLOOP-->.
The following messages can be displayed:
- Unexpected expression type (standard error);
- Incorrect table name (error on the table name);
- An array was expected (the variable is not an array or is a two dimension array);
- The method does not exist;
- Syntax error (when the method is executing);
- Access error (you do not have the appropriate access privileges to access the table or the method).
- 4DENDLOOP expected (the <!--#4DENDLOOP--> number does not match the <!--#4DLOOP -->).
Product: 4D
Theme: Web Server
Binding 4D objects with HTML objects
URLs and Form Actions
4DVAR, 4DTEXT, 4DHTMLVAR, 4DHTML, 4DSCRIPT, 4DINCLUDE, 4DIF, 4DLOOP***