~inc:header.inc~

Dynamic Variables

One of the most basic needs is to provide status information back to the user of your web application. The HTTP server provides for this using dynamic variable substitution callbacks. These commands in your HTML code will alert the server to execute a callback function at that point.

To insert a dynamic variable, place the name of the variable inside of the tilde (~~) character, like this: ~~myVariable~~. When that sequence is found, the server will call the function HTTPPrint_myVariable().

For example, here's the build date of the HEX file programmed in your part:

~builddate~

You can also pass parameters to dynamic variables by placing numeric values inside of parenthesis after the variable name. ~~led(2)~~ will print the value of the second LED. The numeric values are passed as WORD values to your callback function. You can pass as many parameters as you wish to these functions, and if your C code has constants defined, those will be parsed as well.

As an example, here is a binary representation which LEDs are on and off on the board:

~led(7)~ ~led(6)~ ~led(5)~ ~led(4)~ ~led(3)~ ~led(2)~ ~led(1)~ ?

For short outputs (less than 16 bytes) you need only to call the appropriate TCPPut function and return. For longer outputs the output state must be managed through successive calls, which prevents the limited buffer space from being overrun.

As an example, here is the current LCD display (which uses 32 bytes):

~lcdtext~

You can also use dynamic variables to include files. This is useful to save storage space for your pages, since a portion of most pages (header, menu, footer) do not change. By placing ~~inc:filename.inc~~ in your HTML code, the file filename.inc will be read and inserted at this location.

Exercise: Look at code for this page and find how header.inc and footer.inc are used. These files provide a template for the pages to include the same menu, layout, and design elements.

(At this time, dynamic variables are non-recursive, so variables located inside files
included in this manner are not parsed.)

~inc:footer.inc~