Next Previous Contents

4. Syntax

4.1 Pages (.pg)

Pages are main part of application and most of other files are related to them. According to PG variable value masser will try to find file to process regarding path from masser and application configuration. It tries to find file according to PG value with .pg suffix (searches first in paths from application and then from masser):

Basic parts of pages are tags <? and ?>. Code between these tags is processed, other code will be copied to output (see DeltaX::Page for details).

You can use variants of these tags which are described in next sections.

Code in page is local; it means that function or variable in one page is not visible from other pages (in the same or other application), except of global variables and functions.

Example - application APP, file page1.pg:


...
    <?
        sub my_func { print 'page1'; }
    
        my_func();
    ?>
...

Example - application APP, file page2.pg:
...
    <?
        sub my_func { print 'page2'; }
    
        my_func();
    ?>
...

In page page1 string "page1" will be written, "page2" will be written in page page2.

Code <? ... ?>

Code between these two tags is supposed to be perl code and is without changes processed. Developer can assume existing of these global variables:

Next you can use following abbreviations which will be replaced:

Print value <?= ... ?>

This variant is used for inserting value to actual place in page. Code <?=$variable?> is equivalent to <? print $variable; ?>.

Example:


...
    <h1> <?='TXT(app_title)'?> </h1>
...

Comment <?!---- ... ----?>

Comment will be ignored by masser and will not be even copied to output, it's completely thrown.

Opposite to HTML comment (<!---- ... ---->), which will be copied to output.

Include <?!include ...?>

Syntax: <?!include filename [def1[,def2...]]?>

Masser tries to find file with given name similar to pages (.pg):

Code from the file is included into parent file, so you can use any construction from it (include is used often in pages, so you can write to it code which can be written to page itself).

Masser currently not checks for recursive including, so it can lead to indefinite cycling of it!
DefX definitions can be used to control included parts of .inc file using if, else and end constructs.

Example:


   File test.pg:
     <?!include table print?>
   File table.inc:
     <?!use table?>
     <?!javascript table?>
     <?:if print?>
       <?!css table_print?>
     <?:else?>
       <?!css table_screen?>
     <?:end?>

Package <?!package ...?>

Syntax: <?!package filename?>

Masser tries to find file [filename].pkg similar to pages (.pg) this way:

It works similar to include, but is intended to create so-called packages - codes which consist of some parts (for example JavaScript code, CSS and module).

Example:


   <?!include button.inc?>
   <?javascript button?>
   <?!css button?>

DefX definitions can be used to control included parts of .pkg file using if, else and end constructs.

Example:


   File test.pg:
     <?!package table print?>
   File table.pkg:
     <?!use table?>
     <?!javascript table?>
     <?:if print?>
       <?!css table_print?>
     <?:else?>
       <?!css table_screen?>
     <?:end?>

Module <?!use ...?>

Syntax: <?!use filename

Masser tries to find file [filename].pm this way:

This directive is used for including module to page. It can be placed anywhere in page, it's processed during compilation. Module which can be "used" using this directive is very similar to classic perl module, but you can use some masser features - read more about it in one of the following chapters.

Page beginning <?!page_start ...?>

Syntax: <?!page_start [key1=>value1, key2=>value2, ...]?>

Writes start of HTML page (HTTP header and start of page to BODY tag). You can use any parameter which is recognized by start_html() function from CGI module and these special:

This directive must be the first output of page, because it writes HTTP header. In other case server writes Internal Error = bad header.

Example:


...
    <?!page_start title=>'TXT(app_title)', bgcolor=>'#ffffff'?>
...

Important: This function includes JavaScript code and CSS to page, so if you don't use it, tags javascript and css won't work!

Page ending <?!page_end?>

Syntax: <?!page_end?>

This directive writes end of page - end of FORM, BODY and HTML tags. It should be used as the last output of the page.

JavaScript include <?!javascript ...?>

Syntax: <?!javascript [ext:]filename?>

It requests that given JavaScript code to be included into page output. Code is normally written to HEAD tag of the page, but if use ext: prefix in the name, masser will include only reference to a file, otherwise it tries to find the file [filename].js this way:

Its content is read and included into the page.

In JavaScript files you can use following constructions:

You cannot use it in files included with ext: prefix - they are not processed.

Example - file example1.js:


    alert('TXT(error_required)');
    var num_items = PAR(max_results);
    for (var i=0; i<G(nusers); i++) { alert(i); }

Example - page:
    <?!javascript example1?>

This directive can be placed anywhere in the page or in any included file, it's processed during compilation.

CSS include <?!css ...?>

Syntax: <?!css [ext:]filename?>

It requests that given file (it's content) to be included into page code (into HEAD tag). You can use ext: prefix to say to masser to not include code, only reference.

Because of CGI module limitation, you cannot insert more than one CSS file with ext: prefix. If you include more than one, only last will be included.
Otherwise masser tries to find a file [filename].css this way (there is small difference in opposite to other findings: $schema [SCH parameter in page] is used to enable schema switching): File is read and included into the page.

In CSS files you can use following constructions:

You cannot use it in ext: prefixed files - they are not processed.

Example - file example2.css:


    BODY { background-image: url(GLB(img_dir)/backg1.gif); }

Example - page:
    <?!css example2?>

This directive can be placed anywhere in the page or in any included file, it's processed during compilation.

Prepare SQL command <?!statement ...?>

Syntax: <?!statement [dbnum:]filename?>

Prepares given SQL command (using open_statement - see DeltaX::Database). Using dbnum prefix (number from 1 to 5) you can set in which database connection it is to be prepared (if application uses more than one database connection). If not set, statement is prepared in connection number 1.

Masser searches for file [filename].sql this way:

You can use following constructions in it: Example - file MY_STAT.sql:
    SELECT * FROM cats_users WHERE pernr = ? AND last_chgp = _DATETIME_

Example - page:
    <?!statement MY_STAT?>
    <?!statement 2:OTHER_STAT?>
...
    <?
        my $result = $db->perform_statement('MY_STAT');
    ?>

Prepared statements are global for the whole application, but do not influence other running applications. If masser is not in debug mode, each statement is prepared only once, even it's included in more pages. As JavaScript or CSS it can be placed anywhere in code, it's processed during compilation.

Function call <?!do ...?>

Syntax: <?!do filename [parameters]?>

At given place calls - differently from include it will not include whole code - given function, which code is in file filename. Masser tries to find it this way:

It's content must be perl code, you can use PAR, TXT and G replacements and global variables.

Function is global for the whole application, it's invisible for other running applications.

Example - file func.pl:


    my (undef,$par1,$par2) = @_;
    # WARNING! The first argument is always application name!

    if ($par1 > $par2) {
        G(to_print) = 'TXT(is_greater)';
    } elsif ($par1 < par2) {
        G(to_print) = 'TXT(is_lesser)';
    } else {
        G(to_print) = 'TXT(is_equal)';
    }

Example - page:
...
    <?!do func.pl 5,8?>
    <?=$g{'to_print'}?>
...

4.2 Actions (.ac)

Actions are called according to OP variable, which can be empty (no action will be performed), one or more actions (separated by commas).

All actions are performed before pages.

Masser tries to find action according to OP with .ac suffix this way:

Syntax of these files is similar to pages, but in practice it includes only perl code and include and statement directives. It can output text, but it's not recommended.


Next Previous Contents