Access To The Embed Statement Arguments

Access To The Embed Statement Arguments

The arguments and values in the embed statement are accessible at run-time inside the Tclet in the global Tcl array embed_args. The argument names are the array's indices, and the values are stored as the values in the array. You can add your own arguments and values to the embed statement you write in the HTML file, and they will also appear in the embed_args array. The src, width and height arguments are required, but other than that, you have total freedom to invent any new arguments and pass any values you like.

Here is an example Tclet that shows the arguments and values passed in the following embed statement:

<embed src=tcl/embed_args.tcl width=260 height=130 invented=foo>

Here I added an argument invented with the value foo. As you can see, it got passed to the Tclet. You'll also notice that the Tcl plugin adds an argument of its own to the array, the embed_mode argument. It can have one of three values:

hidden, to indicate that there is no window to display in.
full, to indicate that the Tclet displays in the entire web page.
embed, to indicate that a small area is allocated to the Tclet for its display.

You might use this to modify the behavior of the Tclet. For example, the Tclet could display its entire interface in full mode, and when used in embed mode, it could organize its interface as a series of pages in a notebook. This would allow your Tclet to adapt to being used in a variety of different situations.

The above example just lists the arguments and their values. Here is a more useful example; this Tclet uses the value of the background_color argument as its background color. This shows how to customize the behavior of your Tclets with arguments and values passed in the embed statement:

<embed src=tcl/embed_args1.tcl width=260 height=130 background_color=yellow>

Please don't be worried if you examined the source code for the Tclets above and couldn't understand everything they do. This will all become clearer as you go deeper into this site. At this point, the important thing to understand is how to pass arguments and values to your Tclet in an embed statement.