4D v16.3

Semi-dynamic pages

Home

 
4D v16.3
Semi-dynamic pages

Semi-dynamic pages  


 

 

4D's Web server allows you to use semi-dynamic pages

These pages are HTML 'templates' containing 4D Transformation Tags, i.e. a mix of static HTML code and 4D references added by means of transformation tags such as 4DHTML, 4DIF, or 4DINCLUDE. These tags are inserted as HTML type comments (<!--#Tag Contents-->) into the HTML source code.

Note: An alternative $-based syntax is used in certain conditions for 4DHTML, 4DTEXT and 4DEVAL tags in order to make them XML-compliant. For more information, refer to Alternative syntax for 4DTEXT, 4DHTML, 4DEVAL section.

When these pages are sent by the HTTP server, they are parsed and the tags they contain are executed and replaced with the resulting data. The pages received by the browsers are thus a combination of static elements and values coming from 4D. 

You can use programming to give default values to HTML objects by including <!--#4DTEXT VarName--> in the value field of the HTML object, where VarName is the name of the 4D process variable as defined in the current Web process. This is the name that you surround with the standard HTML notation for comments <!--#...-->

Note: Some HTML editors may not accept <!--#4DTEXT VarName--> in the value field of HTML objects. In this case, you will have to type it in the HTML code.

In fact, the syntax <!--#4DTEXT VarName--> allows you to insert 4D data anywhere in the 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.

Here is an example:

  // The following piece of 4D code assigns "4D4D" to the process variable vs4D
 vs4D:="4D4D"
  // Then it sends the HTML page "AnyPage.HTM"
 SEND HTML FILE("AnyPage.HTM")

The source of the HTML page AnyPage.HTM is listed here:

<html>
<head>
    <title>AnyPage</title>
<script language="JavaScript"><!--
function Is4DWebServer(){
    return (document.frm.vs4D.value=="4D4D")
}
function HandleButton(){
    if(Is4DWebServer()){
        alert("You are connected to 4D Web Server!")
    } else {
        alert("You are NOT connected to 4D Web Server!")
}
//--></script>
</head>

<body>
<form action="/4DACTION/WWW_STD_FORM_POST" method="post" name="frm">
<p><input type="hidden" name="vs4D" value="<!--#4DTEXT vs4D-->"</p>
<p><a href="JavaScript:HandleButton()"><img src="AnyGIF.GIF" border=0 align=bottom></a></p>
<p><input type="submit" name="bOK" value="OK"></p>
</form>
</body>
</html>

The <!--#4DTEXT --> tag also allows the insertion of 4D expressions in the pages sent (fields, array elements, etc.). The operation of this tag with this type of data is identical to that with variables. You can also insert HTML code into 4D variables using the 4DHTML tag. Other tags such as 4DIF allow you to control the executed code. A description of all the tags that you can use is found in the 4D HTML Tags section.

Parsing of the contents of semi-dynamic pages sent by 4D takes place when WEB SEND FILE (.htm, .html, .shtm, .shtml), WEB SEND BLOB (text/html type BLOB) or WEB SEND TEXT commands are called, as well as when sending pages called using URLs. In this last case, for reasons of optimization, pages that are suffixed with “.htm” and “.html” are NOT parsed. In order to "force" the parsing of HTML pages in this case, you must add the suffix “.shtm” or “.shtml” (for example, http://www.server.com/dir/page.shtm). An example of the use of this type of page is given in the description of the WEB GET STATISTICS command. XML pages (.xml, .xsl) and WML pages (.wml) are also supported and always parsed by 4D (see XML and WML Support section).

You can also carry out parsing outside of the Web context when you use the PROCESS 4D TAGS command.

Internally, the parser works with UTF-16 strings, but the data to parse may have been encoded differently. When tags contain text  (for example, 4DHTML), 4D converts the data when necessary depending on its origin and the information available (charset). Below are the cases where 4D parses the tags contained in the HTML pages, as well as any conversions carried out:

Action Content analysis of the sent pagesSupport of $ syntax(*)Character set used for parsing tags
Pages called via URLsX, except for pages with “.htm” or “.html” extensionsX, except for pages with “.htm” or “.html” extensionsUse of charset passed as parameter of the "Content-Type" header of the page. If there is none, search for a META-HTTP EQUIV tag with a charset. Otherwise, use of default character set for the HTTP server
WEB SEND FILE command callX-Use of charset passed as parameter of the "Content-Type" header of the page. If there is none, search for a META-HTTP EQUIV tag with a charset. Otherwise, use of default character set for the HTTP server
WEB SEND TEXT command callX-No conversion necessary
WEB SEND BLOB command call X, if BLOB is of the “text/html” type-Use of charset set in the "Content-Type" header of the response. Otherwise, use of default character set for the HTTP server
Inclusion by the <!--#4DINCLUDE--> tagXXUse of charset passed as parameter of the "Content-Type" header of the page. If there is none, search for a META-HTTP EQUIV tag with a charset. Otherwise, use of default character set for the HTTP server
PROCESS 4D TAGS command callXXText data: no conversion. BLOB data: automatic conversion from the Mac-Roman character set for compatibility

(*) The alternative $-based syntax is available for 4DHTML, 4DTEXT and 4DEVAL tags (see Alternative syntax for 4DTEXT, 4DHTML, 4DEVAL section).

4D supports JavaScript source code embedded into HTML documents, and also JavaScript .js files embedded in HTML documents (for example <SCRIPT SRC="...").

Using WEB SEND FILE or WEB SEND BLOB, you send a page that you have prepared in an HTML source editor or built programmatically using 4D and saved as a document on disk. In both cases, you have full control of the page. You can insert JavaScript scripts in the HEAD section of the document as well as use scripts with the FORM markup. In the previous example, the script refers to the form "frm" because you were able to name the form. You can also trigger, accept, or reject the submission of the form at the FORM markup level.

Note: 4D supports Java applets transport.



See also 

4D Transformation Tags

 
PROPERTIES 

Product: 4D
Theme: Web Server

 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)