There is another 4D Tag that is commonly used with 4DIF, 4DELSE, and 4DENIF. That tag is 4DINCLUDE. 4DINCLUDE is used to insert the contents of one HTML file into the the page of another at run-time. We are going to modify our example to now use a 4DINCLUDE.
Once again open the index.shtml file in your text editor. Replace the contents of this file with the following:
<html>
<head>
<title>4D Web Tags</title>
</head>
<body>
<!--4DIF (random%2=0)-->
<!--4DINCLUDE index_even.shtml-->
<!--4DELSE-->
<!--4DINCLUDE index_odd.shtml-->
<!--4DENDIF-->
</body>
</html>
Save the file.
Create new textfile, and enter the following into it:
<br>
<b>This is the contents of the "even" file.</b>
Save it with the name "index_even.shtml" in the WebFolder.
Create new textfile, and enter the following into it:
<br>
<i>This is the contents of the "odd" file.</i>
Save it with the name "index_odd.shtml" in the WebFolder.
Go back to your web browser, and once again enter "127.0.0.1" into the address bar. If you still see "This is even!" or "This is odd!" then hold down the Control key (or Command key, on Macintosh) to make sure the browser doesn't look in its cache. You should now be seeing the messages presented in the index_even.shtml or index_odd.shtml files displayed in the web browser.
Of course, this example is very simplistic. You can use much bigger files with 4DINCLUDE. Another common use of 4DINCLUDE is with "headers" and "footers" - standard stuff that you want to put at the beginning or end of HTML files used in your application.
The file that you specify for 4DINCLUDE can, of course, include other 4D Tags (4DIF, 4DENDIF, 4DVAR, etc.) and they will be executed. The one tag that you cannot use in file in an included file is another 4DINCLUDE.
Now return to your web browser and again enter "127.0.0.1" into the Address field. You should randomly see the "even" or "odd" file contents displayed each time you hit reload.
Now that you have completed this tutorial, you should have a basic understanding of how the 4DIF, 4DELSE, and 4DENDIF tags work. You should also be comfortable with using the 4DINCLUDE tag to insert the contents of one page into another as it is built. The knowledge you have gained will be used in later tutorials in this series.
Previous Step 1 2 3