The expert corner

From GeneWeb
Jump to navigation Jump to search
150px-Geographylogo svg.png Language:   English

Template programming (%if; ... %end;)

The template mechanism provides a very powerful mechanism to construct HTML (or other) pages according to the content of a GeneWeb base. This section is not intending to give an exhaustive description of the corresponding language. Through some examples extracted from gw/etc/perso.txt, it provides a glimpse of the possibility. The last two examples are extracted from a template that generates LaTeX rather than HTML.

For further analysis, explore the various other template files, and on last resort, explore the Ocaml source files!!

     %if;has_qualifiers;%public_name; %qualifier;
     %else;%public_name; %surname;%end;
     %if;has_qualifiers;%first_name; %qualifier;
     %else;%first_name; %surname;%end;
%define;married_to(sexx, date_place)
 %if;(sexx = 0 or sexx = 2)
   %if;are_married;[*married%t to:::date_place]0%nn;
   %elseif;are_not_married;[*relationship%t to:::date_place]0%nn;
   %elseif;are_engaged;[*engaged%t to:::date_place]0%nn;
   %elseif;is_no_sexes_check;[*relationship%t to:::date_place]0%nn;
   %elseif;is_no_mention;date_place [*with]%nn;
   %if;are_married;[*married%t to:::date_place]1%nn;
   %elseif;are_not_married;[*relationship%t to:::date_place]1%nn;
   %elseif;are_engaged;[*engaged%t to:::date_place]1%nn;
   %elseif;is_no_sexes_check;[*relationship%t to:::date_place]1%nn;
   %elseif;is_no_mention;date_place [*with]%nn;
%if;(bvar.can_send_image != "no" and image = "" and first_name != "?" and surname != "?")
     <li><a href="%prefix;m=SND_IMAGE;i=%index;" class="add_portrait">
            %if;(auto_image_file_name != "")[*modify picture]%else;[*add picture]%end;
%define;hgindex(alxx, snxx, fnxx, occxx)
  %if;(alxx = "0")
    %if;(occxx = "0")
      \index{snxx, fnxx}
      \index{snxx, fnxx (occxx)}
    %if;(occxx = "0")
      \index{alxx, voir snxx, fnxx}
      \index{alxx, voir snxx, fnxx (occxx)}
    {\it {\bf %alias;}}%apply;hgindex(alias, surname, first_name, occ)\\%nl;

This list does not claim to be exhaustive (but pretty close!!).

"image" if 

Macros (%x)

See Macros for a description of their use.

Below is the result of calling all 26 lower case possible macros: This table is automatically generated by inserting a bit of HTML/GeneWeb code into the notes of one person in your base. The corresponding code is here

Table of GeneWeb macros.

Commands (m=XXX)

List of the commands appearing in URL with the form:


This list does not claim to be exhaustive, and does not "explain" what each command does!

"DOC" (* obsolete *)
"MOD_WDOC"  (* obsolete *)
"MOD_WDOC_OK"  (* obsolete *)
"PS" P
"WDOC" (* obsolete *)

Variables (evar and bvar)

GeneWeb proposed a general purpose mechanism allowing the user/programmer to extend at will the notion of variable described here.

If a new variable is defined in the .gwf configuration file, then it will be possible to test for the value of this variable in the context of a template file. For instance, if we have added


in .gwf, then the following code in the template will be able to perform some specific action:

%if; (bvar.new_var = "sometext" ) 
    ... perform some specific action ...

Similarly, if we have added a new variable in the URL of the query to GeneWeb (localhost:2317/base?p=first-name;n=last-name;lang=fr;tree=3, then it is possible to test for this variable with code such as:

%if; (evar.tree = 3 ) 
    ... display 3 generation tree ...

The value itself of such variables can be inserted in the body of a template by typing %evar.tree;, for instance:

<title>Tree with %evar.tree; generations</title>