The expert corner

From GeneWeb
Revision as of 10:11, 5 May 2018 by Henri83 (talk | contribs) (Update in template functions list)
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!!

Programming constructs:

 %define(p1, p2) ... %end;
 %if;(cond) [%elseif;] [%else;] %end;
 %let;xxx;zzz%in;
 %foreach; ... %end;
 %for;i;0;n;... %end;
 %apply;xxxx(p1, p2) or
 %apply; ... [%with;... [%and;] ...%end;]
 %nl; %nn; %sp; %sq;

Functions callable with %apply:

 capitalize
 language_name
 nth("aaa"/"bbb"/"ccc"/"ddd", n)
 nth_c("abcdef", n)
 blue_of_hsv
 red_of_hsv
 green_of_hsv

Arithmetic and booleans:

 +, -, /, *, %, =, !=, <, <=, >, >=, "and", "or", "not", "in"

WARNING: all functions may not be fully available depending on the execution context!

 <title>%nn;
   %if;has_public_name;
     %if;has_qualifiers;%public_name; %qualifier;
     %else;%public_name; %surname;%end;
   %else;
     %if;has_qualifiers;%first_name; %qualifier;
     %else;%first_name; %surname;%end;
   %end;
 </title>
%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;
   %end;
 %else;
   %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;
   %end;
 %end;
%end;
%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;
          </a>
     </li>
%end;
 
%define;hgindex(alxx, snxx, fnxx, occxx)
  %if;(alxx = "0")
    %if;(occxx = "0")
      \index{snxx, fnxx}
    %else;
      \index{snxx, fnxx (occxx)}
    %end;
  %else;
    %if;(occxx = "0")
      \index{alxx, voir snxx, fnxx}
    %else;
      \index{alxx, voir snxx, fnxx (occxx)}
    %end;
  %end;
%end
%foreach;alias;
    {\it {\bf %alias;}}%apply;hgindex(alias, surname, first_name, occ)\\%nl;
%end;

This list does not claim to be exhaustive (but pretty close!!). A good way to understand the semantic of these commands is to explore the template files and observe how they are used (grep is your friend).


"access_by_key"
"access"
"action"
"age"
"alias"
"add_in_sorted_list"
"add_in_sorted_listb"
"add_in_sorted_listc"
"anc_sosa" 
"ancestor_level" 
"ancestor_level2" 
"ancestor_surname" 
"ancestor_tree_line" 
"ancestor" 
"are_divorced"
"are_engaged"
"are_married"
"are_not_married"
"are_separated"
"auto_image_file_name"
"baptism_date" 
"baptism_note"
"baptism_place"
"baptism_witness" 
"base"
"birth_date" 
"birth_note"
"birth_place"
"birth_witness" 
"birth_witness" 
"birthday"
"border"
"browsing_with_sosa_ref"
"burial_date" 
"burial_note"
"burial_place"
"burial_witness" 
"bvar"
"cancel_links"
"canton"
"cell"
"cgi"
"charset"
"child_cnt" 
"child_name"
"child" 
"colspan"
"comment"
"commit"
"commit_date"
"compilation_time"
"computable_age"
"computable_death_age"
"computable_marriage_age"
"connections"
"consanguinity"
"count"
"country"
"county"
"cousin_level" 
"cremated_date" 
"cremation_place"
"cremation_witness" 
"date_begin" 
"date_end" 
"date"
"dates"
"day"
"death_age"
"death_date" 
"death_note"
"death_place"
"death_witness"
"decoded"
"desc_level"
"descendant_level" 
"died" 
"district"
"divorce_date"
"doctype"
"doctype_transitionnal"
"empty_sorted_list"
"empty_sorted_listb"
"empty_sorted_listc"
"enclosing"
"env"
"env_binding"
"evar"
"event_witness_kind" 
"event_witness_relation_kind" 
"event_witness_relation" 
"event_witness" 
"event"
"false"
"fam_access"
"family_cnt" 
"family" 
"father_age_at_birth" 
"father_sosa"
"father" 
"first_name_alias"
"first_name_key_strip"
"first_name_key_val"
"first_name_key"
"first_name"
"fnotes"
"fsources"
"fwitness"
"has_aliases"
"has_baptism_date" 
"has_baptism_note"
"has_baptism_place" 
"has_baptism_witnesses"
"has_birth_date" 
"has_birth_note"
"has_birth_place" 
"has_birth_witnesses"
"has_burial_date"
"has_burial_note"
"has_burial_place" 
"has_burial_witnesses"
"has_children"
"has_comment"
"has_consanguinity"
"has_cremation_date"
"has_cremation_place" 
"has_cremation_witnesses"
"has_date"
"has_death_date"
"has_death_note"
"has_death_place" 
"has_death_witnesses"
"has_event"
"has_families" 
"has_first_names_aliases"
"has_fnotes"
"has_fsources"
"has_fwitness"
"has_history"
"has_image" 
"has_linked_page"
"has_linked_pages"
"has_marriage_note"
"has_nephews_or_nieces" 
"has_nobility_titles" 
"has_note" 
"has_notes"
"has_occupation" 
"has_parents" 
"has_place"
"has_pnotes"
"has_possible_duplications" 
"has_psources"
"has_public_name"
"has_qualifiers"
"has_referer"
"has_relation_her"
"has_relation_him"
"has_relations"
"has_siblings"
"has_sosa"
"has_sources"
"has_spouse"
"has_src" 
"has_surnames_aliases"
"has_witnesses"
"hexa"
"highlight"
"history_file"
"hours"
"ident"
"ident_key"
"image_prefix"
"image_html_url" 
"image_medium_size"
"image_size" 
"image_small_size" 
"image_url" 
"image"
"incr_count"
"incr_count1"
"incr_count2"
"ind_access"
"index" 
"interval"
"is_buried"
"is_center"
"is_cremated"
"is_dead"
"is_descendant"
"is_empty"
"is_female" 
"is_first"
"is_invisible"
"is_last"
"is_left"
"is_male"
"is_no_mention"
"is_no_sexes_check"
"is_printed_by_template"
"is_private" 
"is_public" 
"is_restricted" 
"is_right"
"is_self"
"is_sibling_after" 
"is_sibling_before" 
"is_top"
"item"
"just_friend_wizard"
"lang"
"lazy_force"
"lazy_printed"
"left"
"level"
"linked_page"
"key"
"manitou"
"mark_descendants"
"marriage_age"
"marriage_date" 
"marriage_note"
"marriage_place"
"max_anc_level"
"max_cous_level"
"max_desc_level"
"minutes"
"misc_names"
"month"
"mother_age_at_birth" 
"mother_sosa"
"mother" 
"name"
"nb_children"
"nb_children_total"
"nb_events" 
"nb_families" 
"nb_ind"
"nb_times" 
"next_item" 
"nobility_title"
"note"
"notes"
"number_of_ancestors" 
"number_of_descendants" 
"number_of_subitems"
"occ"
"occupation"
"octal"
"on_baptism_date"
"on_birth_date"
"on_burial_date"
"on_cremation_date"
"on_date"
"on_death_date"
"on_marriage_date"
"origin_file"
"other"
"parent" 
"place_key" 
"place"
"pnotes"
"prec"
"prefix"
"prefix_2"
"prefix_base"
"prefix_base_2"
"prefix_base_password"
"prefix_base_password_2"
"prefix_no_templ"
"prefix_no_iz"
"prefix_no_pmod"
"prefix_no_wide"
"prefix_no_lang"
"prefix_no_all"
"prev_fam_father"
"prev_fam_index"
"prev_fam_mother"
"prev_family" 
"prev_item" 
"public_name"
"pvar"
"qvar"
"svar"
"tvar"
"qualifier"
"region"
"related_type"
"related"
"relation_her" 
"relation_him" 
"relation_type"
"relation" 
"reset_count"
"reset_count1"
"reset_count2"
"reset_desc_level"
"right"
"same"
"seconds"
"self" 
"set_infinite_desc_level"
"sex"
"slash_baptism_date"
"slash_birth_date"
"slash_burial_date"
"slash_cremation_date"
"slash_death_date"
"slash_divorce_date"
"slash_marriage_date"
"sorted_list_item"
"sorted_listb_item"
"sorted_listc_item" 
"sosa_access"
"sosa_in_list"
"sosa_link"
"sosa_ref" 
"sosa" 
"source_type"
"source"
"spouse"
"src"
"static_max_anc_level"
"static_max_desc_level"
"sueprvisor"
"surname_alias"
"surname_begin"
"surname_end"
"surname_key_strip"
"surname_key_val"
"surname_key"
"surname"
"title" 
"today"
"town"
"township"
"true"
"url"
"user"
"v"
"val"
"var"
"version"
"wedding_birthday"
"wid_hei"
"witness_relation" 
"witness"
"wizard"
"year"

Note for has_event (v7)

Note that the has_event function does not consider birth, baptism, death and burial as "events" per se (as they are often already listed in the personnal data of the individual). If you want those events to be taken into account in this function, then you have to add has_events=always in your .gwf parameter file.

Note also that if has_events=never, then has_event always returns False.

JavaScript

JavaScript can be inserted anytime within templates. JavaScript code may contain template commands as in:

<script type="text/javascript">
  <!--
  function over1(xx)
  {
   document.getElementById(xx).style.%if;(evarso="on")outline="#C0FEFF solid 6px"%else;backgroundColor="#CBFECE"%end;;
   return false;
  }
  function out1(xx)
  {
   document.getElementById(xx).style.%if;(evarso="on")outline="none"%else;backgroundColor=""%end;;
   return false;
  }
  -->
</script>

Note that GeneWeb does not perform any language interpretation ([text to be translated]) within HTML comments!

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:

%sm=COMMAND;p=param1;n=param2;

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

"A"
"ADD_FAM" 
"ADD_FAM_OK" 
"ADD_IND" 
"ADD_IND_OK"  
"ADD_PAR" 
"ANM" 
"AN"
"AD"
"AM"
"AS_OK" 
"B" 
"C"
"CAL" 
"CHG_CHN" 
"CHG_CHN_OK" 
"CHG_FAM_ORD" 
"CHG_FAM_ORD_OK" 
"CONN_WIZ" *
"D"
"DAG" *
"DEL_FAM"  
"DEL_FAM_OK"  
"DEL_IMAGE"  
"DEL_IMAGE_OK" 
"DEL_IND"  
"DEL_IND_OK" 
"DOC" (* obsolete *)
"FORUM"
"FORUM_ADD"
"FORUM_ADD_OK"
"FORUM_DEL"
"FORUM_P_P"
"FORUM_SEARCH"
"FORUM_VAL"
"FORUM_VIEW"
"H"
"HIST" 
"HIST_CLEAN"  
"HIST_CLEAN_OK" 
"HIST_DIFF" 
"HIST_SEARCH" 
"IM" *
"IMH" *
"INV_FAM"  
"INV_FAM_OK"  
"KILL_ANC" 
"LB" 
"LD" 
"LINKED"
"LL" 
"LM" 
"LEX" 
"MISC_NOTES" 
"MISC_NOTES_SEARCH" 
"MOD_DATA"  
"MOD_DATA_OK"  
"MOD_FAM"  
"MOD_FAM_OK"  
"MOD_IND"  
"MOD_IND_OK" 
"MOD_NOTES"  
"MOD_NOTES_OK"  
"MOD_WDOC"  (* obsolete *)
"MOD_WDOC_OK"  (* obsolete *)
"MOD_WIZNOTES" *
"MOD_WIZNOTES_OK" *
"MRG" 
"MRG_DUP"  
"MRG_DUP_IND_Y_N" 
"MRG_DUP_FAM_Y_N" 
"MRG_FAM"  
"MRG_FAM_OK"  
"MRG_MOD_FAM_OK" 
"MRG_IND"  
"MRG_IND_OK"  
"MRG_MOD_IND_OK" 
"N"
"NG"
"NOTES" 
"OA" 
"OE" 
"P"
"POP_PYR" 
"PS" P
"R"
"REQUEST" 
"RL" 
"RLM" *
"S" 
"SND_IMAGE"  
"SND_IMAGE_OK" 
"SRC" *
"STAT" B
"CHANGE_WIZ_VIS" *
"TT" 
"U" 
"VIEW_WIZNOTES" 
"WDOC" (* obsolete *)
"WIZNOTES" *
"WIZNOTES_SEARCH" *

Commands marked with a * are documented below:

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

new_var=some-text

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 ...
%end;

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 ...
%end;

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>

The special variable var is treated in the following fashion within notes, sources and comments: If you define in the .gwf file a variable {{{1}}}, then invoquing the macro %vtext; in a note or a template will produce the text some_text as in the following example:

var_who=Bond, James Bond

"My name is %vwho;." in a note will be transformed into "My name is Bond, James Bond.".

This feature is used by some to facilitate signature of sources. The .gwf file contains a list of var_nickname definitions whose value is a full name and possibly a pointer to a page containing more detailed information:

var_henri=<a href="http://site/base?p=Firstname;n=lastname">First_name Lastname</a>

(no %x or %macro; in the value of the parameter!!).

Building trees through direct url construction

See trees or trees/fr


GeneWeb Manual

Rembrandt Old Man Reading a Book.jpg

Use and manage genealogical databases

Technical annex