Introduction to ASP-db Template Programming Gold

Magic Template is one of the highlights of ASP-db. It enables user to design free form reports and input screens using a visual editor like FrontPage in conjunction with a very small stub ASP-db asp file. It  also provides a vehicle for data which is extracted from various sources to be placed onto the template to compose a dynamic report. Templates can also be delivered via E-mail (ASPdbSendMail) using information stored in a database. The following demonstrates a few examples using minimum coding.

The MagicTemplate is an ASCII file containing valid HTML codes and special datafield tags. There are no restrictions in the file extension but it is recommended that .html or .html should be used for the obvious reasons. In case of the .html file <!-- #include File="Local File Name" --> is supported. (Virtual is not supported at this time) There are two ways to apply templates -

Level 1: Use a template to substitute the standard FORM, FILTER, ADD, or UPDATE screen with a user-defined screen.

Level 2: Generate individual objects without any display and then use a SendTemplate to consolidate them.

Each method is very powerful in its own way.

It applies to FORM, ADD, UPDATE, DELETE and FILTER operations. There is also a special provision to support the GRID operation. MagicTemplate enables user to easily customize their Input and output formats of their display. The objects that can be "Dropped" into the template tags includes grids, records, grid rows, field values, Lists, Blocks. There are numerous control attributes available to users.

Template related properties and keywords –

These 5 'template' properties when defined will "intercept" the original display and branch into the template display. dbButtonImages will pickup images from dbImageDir unless directory is specified in the items. (to be used with "Level 1" templates):

This property can be used to generate objects for use in a template:

This property suppresses the display of the unit and allow data objects like GRID, BLOCKS etc.. to accumulate before the final placement on the template:

This method will send a template to the browser together with all the filled out tags:

Template tag format - [[Tagname:Attribute1: Attribute2: Attribute3]]

Tag Format

Function

[[FilterSubmitButton]] Place Filter submit button
[[ResetButton]] Place Reset button
[[AddSubmitButton]] Place Add submit button
[[UpdateSubmitButton]] Place Update submit button
[[DeleteSubmitButton]] Place Delete submit button
[[ReturnButton]] Place "Cancel" Edit button
[[FormTag]] Place the <FORM> tag. Do not place this tag yourself.
[[/FormTag]] Place the </FORM> tag. This one you can do yourself.
[[ASPdb_Layout_Unit_ID]] Place Grid object generated by dbMagicLayout.
[[Var:S|F X:HTML]] Place a block of HTML code when a field (F) or session variable’s (S) value in non-blank. Only [S,O,Q] variables can be used in the HTML statement.
[[Today:DateFormat]] Place today’s date. [[Today:MM/DD/YY HH:MM::SS]]
[[Validate:vFldName, vFormName, vType, vMask, vEvent, vDefault, vMin, vMax, vAddParam, vRequired]] Place an input object with validation parameters. dbValidatorParams must be defined in conjunction of this. (Not implemented yet!)

 

Attribute

Function

Example

[B]
Input
Indicates the field cannot be blank during SUBMIT. Must be used with [U] [[EmployeeID:UB]]
[C]
Common
Return the Boolean value in form of the word "Checked" or a space for Radio and Checkbox <INPUT TYPE="Checkbox" VALUe = [[discontinued:W]] [[discontinued:C]]>
[D]
Form
Filter
Produce a drop box according to the db???DropFlds. Lookup is honored. [[Manufacturer:D]]
[F]
Common
Field variable [[Var:FX:HTML_Code]]
[H]
Edit
Hidden field [[Secret:H:Secret]] =<INPUT TYPE=HIDDEN NAME=Secret VALUE=’Value of field secret’>
[I]
Common
Display Block of HTML code according to the conditions. See example below. [[Var:IFS:OP: CmpValue: HTML]]
[L]
Text
Memo
Return as List Object [[MemoField:L:;:+++]] means separate paragraph and list with (+++) and separate list items with (;). Without +++ equal LIST only.
[[SL]] = Display HTML only if value of S/F var is non-blank.
[M]
Form
Filter
Send to be processed by MagicCell. LookUp will be performed with ot w/o dbMagicCell property.  [[ReportsTo:M]] means process the ReportsTo field through the MagicCell filter. Remember to set the appropriate MagicCell property (Grid, Form etc.)
[O]
Common
Form Variable [[Var:O]]=request.Form("Var")
[Q]
Common
QueryString Variable [[Var:Q]] = resquest.Querystring("Var")
[S]
Common
Session variable. All grid objects are of [S] type. Optional "Format" for numeric data display.  [[Var:S:Format]]=session("Var")
[U]
Update
Add
User defined input fields for Add and update. Must be defined before all the tags. Better to be in a comment section. [[ShippedDate:U]]
[W]
Common
Balance single and double quotes in the field’s value. Do not issue wrapping quotes in VALUE <INPUT TYPE =TEXT VALUE=[[Field"W]]>
[X]
Common
Display HTML only if value of S/F var is non-blank.
(This tag is obsolete and replaced by the "I" tag)
[[Var:S or F X:HTML_Code]]
None
Common
Return raw field value [[Price]]

 

Level 1 template example

This example illustrates using a template to replace the FORM part of the display. A logical condition also used to selectively display information according to the field value.

<%
Set X=Server.CreateObject("ASP.DB")
X.dbQuickProps="3;NWIND;;Dual-horiz;4;;/images/;ACCESS;4;1;1"
X.dbNavigationItem="top,bottom,prev,next"
X.dbSQL="Select * from products"
X.dbGridDisplayFlds="0,1,5,discontinued"
X.dbFormDisplayFlds="0,1,5,discontinued"
X.dbFormTemplate="Form48.htm"
X.ASPDB
%>
File=form48.htm

<H3>FORM Template [[:I]] Tag Demo</H3>
ProductID: [[ProductID]]<BR>
ProductName: [[ProductName]]<BR>
Unit Price: [[UnitPrice]]<BR>
ProductName: [[ProductName]]<BR>

[[Discontinued:IF:EQB:True: <P>This Item is discontinued]]
[[Discontinued:IF:EQB:False: <P>This Item is Available]]
<BR>
[[ProductID:IF:ST:1|3|4:<!-- #include file="inc1.inc" -->]]
[[ProductID:IF:EQN:2:<!-- #include file="inc2.inc" -->]]

File=inc1.inc

This is include file 1

File=inc2.inc

This is include file 2

 

 

Examples –

[[Discontinued:IF:EQB:True: <P>This Item is discontinued]]
[[Discontinued:IF:EQB:False: <P>This Item is Available]]
[[ProductID:IF:EQN:1:<!-- #include file="inc1.inc" -->]]
[[ProductID:IF:EQN:2:<!-- #include file="inc2.inc" -->]]

[[Manufacturer]] – Retrieve the "Manufacturer" field as RAW.

[[Price:M]] – Retrieve the "Manufacturer" field according to -> X.dbFormMagicCell="Price,,Format=[currency]"

[[Car:D]] – Create a Drop Box of the "Car" field according to -> X.dbfilterDropFlds="Car,,carspecs,car"

[[logo:M]] will retrieve the embedded gif image in pub_info table according to -> X.dbBLOB="Logo,image/gif,browser,0"

[[FormTag]] [[/FormTag]] – Place a pair of form tags around the FORM. You can have multiple Submits.

**** DO NOT PLACE [[FormTag]] [[/FormTag]] in Comments *****

[[Expensive:U]] - Indicates Expensive is a user prepared tag. [U] can be within comment tags.

[[MyVar_123:S]] – Place a server variable (exported).

A special dual mode -

X.dbMode="dual"
X.dbMagicLayout="SELECTBOX;[#0#] #1#"
X.DbFormTemplate="FormTemplate.htm"

This would produce a drop down box drive the Form which is a very useful combination.

An Example-

File=Employee.asp

<%
dir="e:\vdata\"
Set X= Server.CreateObject("Asp.DB")
X.dbQuickProps="123;NWIND;EMPLOYEES;dual;4;;;ACCESS;5"
X.dbFormTemplate=dir & "EP-EX1-form1.htm"
X.dbMagicLayout="1;GRID"
X.ASPdb
%>

File= EP-EX1-form1.htm

[[formnavigationbutton]]<BR>
[[ASPdb_Layout_123_1:S]]<BR>
[[formnavigationbutton]]

 

Method Syntax

Obj.ASPdbSendTemplate(Template-Path)

This method send a template file to the browser. Before this final "CheckOut", previous modules should already construct the required objects like grid, chart, list, blocks etc. to correspond to the tags in the template.

Parameters

Template-Path Physical path of the ASCII template  file. There is no limitation of the file extension except that using .htm or .html will be easier for browser viewing. A visual HTML editor like Front Page is highly recommended.