KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Embedding HTML code via variables
PRODUCT: 4D | VERSION: | PLATFORM:
Published On: September 17, 1999

4D allows you to insert information into a HTML page that is being served by the 4D Web Server. This is accomplished by embedding a comment tag in the HTML page with the same name as the variable in the method.

The following code shows an example of embedding an age value into a web page called "age_page.htm".

Here's the 4D Method "W_ShowAge":

Now, here's the HTML page ("age_page.htm")

<HEAD></HEAD>

<BODY><P>You are <!--4DVAR vAge--> years old!</P></BODY>

</HTML>

The comment tag with the like named variable allows 4D to insert dynamic information into a web page. But there might be situations where you'd like to insert HTML code instead of text. This can be accomplished very easy by modifying the 4D method. If you intend on inserting HTML code instead of text, you must use Char(1) as the first character in the variable that is to be inserted in the page. This tells 4D that the variable is HTML code and not plain text.

Let's use the example above but instead of plain text, we'll send HTML code. The HTML code will make the color of the age red. We will not have to modify the HTML page "age_page.htm".

Here's the new 4D Method "W_ShowAge"

Using this method you can insert any type of HTML code into any HTML page being served by 4D's Web Server. If taken a step further, you could write the complete HTML page in a variable, put the variable into a blob, and send the blob to the browser via Send HTML Blob.

Cut and Paste the following code example into your
own 4D project

4D Method "W_ShowAge":
C_Text(vAge)
C_Longint($age)

$age:=89

vAge:=String($age)

Send HTML file("age_page.htm")
Here's the new 4D Method "W_ShowAge"
C_Text(vAge)
C_Longint($age)

$age:=89

vAge:=Char(1)
vAge:=vAge+""+String($age)+"

Send HTML file("age_page.htm")