HTML Templates

Each template is defined by a number of sections detailing the input fields, which fields are required, and what to do with the given data.

A line beginning with a '#' is a comment and will be skipped.

Template definition

[name]
Template name
[fields]
name    helpfile    label    type    name2 ....
[required]
type    Error message    field names ...
[rules]
if (expressions) { definitions }    definition ...
[html]
html code
using %%variables%% defined earlier
[js]
javascript code
using %%variables%% defined earlier

Sections

Name

The name of the template. This will shown when inputting data (e.g. “new template”), and will also be used as a prefix for the generated HTML and JS files (e.g. new_13445.html.js)

Fields

A list of input fields available for data input. Each field is defined on one line in the template source file and consists of a tab separated list of values: name helpfile label type

Name is the name of the variable that will contain the inputted data.

Helpfile is either ”-” or the name of a file, located in the help directory (without the .html prefix) describing in detail the specifics of input field (e.g. “clickTag”)

Label is the explaining text label for the field (e.g. “Upload HTML file”)

Type is the type of the field: string, upload, input or choice.

  • Choice allows the user to select one of a list of values. The alternatives are given as a tab separated list after the choice keyword. (e.g. choice yes no)
  • String is used for regular text input, and can have an option default value
  • Input is like string, but will be used instead of a label for the following field. The value given in its label field will be used as a default value for the field.
  • Upload lets the user upload a file. Use the predefined field names userfile0, userfile1 and userfile2 for these fields. The names of the uploaded files will then be found in file0, file1 and file2.
Required

A list of requirements specifying which fields has to contain data. Each requirement is defined on one line in the template source file and consists of a tab separated list of values: type error message field list

Type is one of

  • simple - This field must be present
  • minone - At least one of these fields must be present
  • maxone - At most one of these fields must be present
  • either - Exactly one of these fields must be present - shorthand for minone and maxone.
  • all - If one of these fields is present, all of them must be.

Error message is printed to the user if this requirement isn't met.

Field list contains a tab separated list of fields for this requirement - one field for the simple rule, at least two fields for the others.

Rules

A list of variable definitions, on the syntax if (expression) { definitions }

or the unconditional version definitions

An expression can be:

  • def varname - true if the variable varname has been defined
  • varname == value - true if the variable can be evaluated to value
  • not expression - true if the expression evaluates to false
  • (expression) and (expression) - true if both expressions evaluates to true

If the expression evaluates to true - or the unconditional version is uses - the definitions will then be evaluated. The definitions are a tab separated list of varname = 'value' assignments. The right-hand side values will go through variable substitution, where each occurrence of varname will be replaced with the current value of the variable varname, or removed from the string if the variable is undefined. The left-hand side variable names do not use the surrounding ... notation. Rules are evaluated top-down.

Examples:
my_width = '%%width%%px;'
if (def %%file0%%) { a_href = '<a href="_P_%%file0%%">click here</a>' }

HTML

This section contains the HTML code to be written to the .html file. It can include the JavaScript section by using the js notation on a line of its own.

Examples:
<script language="JavaScript" type="text/javascript">
%%js%%
</script>
<noscript>
<a href="%%url%%" target="%%target%%">%%text%%</a>
</noscript>

JS

This section contains the JavaScript code to be written to the .html.js file.

Built-in variable names
  • name - will be the name of the creative
  • userfile0…userfile2 - are automatically uploaded
  • file0…file2 - will contain the names of the uploaded files
  • admatcher - the admatcher used
  • cre_width, cre_height - the pixel dimensions of the campaign

Example template

[name]

Popup

[fields]

name	-	Name of creative	string
text	-	Enter HTML url	string
userfile0	-	..or upload HTML	upload
width	-	Popup width	string
height	-	Popup height	string
type	-	Type of popup	choice	popup	popunder

#scrollbar	-	Visible scrollbars	choice	yes	no
#toolbar	-	Browser toolbar	choice	yes	no
#location	-	Browser location field	choice	yes	no
#resizable	-	Popup resizable	choice	yes	no

[required]

#either	You need either a HTML url or an uploaded HTML	text	userfile0
all	Either specify both width and height, or leave both empty	width	height
minone	You need either a HTML url or an uploaded HTML	text	userfile0
maxone	Either upload a HTML file or specify an URL, not both.	text	userfile0

[rules]

if (def %%text%%) { html = 'EASLink=%%text%%' }
if (def %%file0%%) { html = 'EASFile=%%file0%%' }

# Build the "options" expression
if (def %%width%%) { options = 'width=%%width%%,' }
if (def %%height%%) { options = '%%options%%height=%%height%%,'}
# options = '%%options%%toolbar=%%toolbar%%,location=%%location%%,'
# options = '%%options%%scrollbars=%%scrollbar%%resizable=%%resizable'

# Depending on the type of popup, decide which window to blur and which to focus.
if (%%type%% == 'popup') { focus = 'win2.focus();' }
if (%%type%% == 'popunder') { blur = 'win2.blur();'	focus = 'window.focus();' }

[js]

win2 = window.open("%%html%%", "", "%%options%%");
%%blur%%
%%focus%%

[html]

<script language='JavaScript' type='text/javascript'>
<!--
%%js%%
//-->
</script>
Cxense © 2012 | Support