First off, check out the
template documentation. Bookmark it too.
I'll try to explain a few things with one of my own templates.
Here's part of a somewhat simple GPM template made to display icons for various fanfics rather than a zillion different column icon rules:
Code:
program:
f = $#fanficcat;
strcat(
if "^Fallout$" inlist f then 'fallout.png:' fi,
if "^Half-Life$" inlist f then 'halflife.png:' fi,
if "^(Mass Effect Trilogy|Mass Effect: Andromeda)$" inlist f then 'masseffect.png:' fi,
if "^The Elder Scrolls$" inlist f then 'theelderscrolls.png:' fi,
if "^Pokémon$" inlist f then 'pokemon.png:' fi,
if "^Portal$" inlist f then 'portal.png:' fi,
)
Defining things:
f = $#fanficcat;
Here, I am telling the template that 'f' means the value of the #fanficcat column. A column 'field reference' can be preceded with $ or $$; the former is input, while the latter is 'raw' input (the latter mostly matters for datetimes, which have a lot of different formattings).
While in the fanfic icon example I'm just using it as shorthand, here's another example from a more complicated template.
Here, I use regular expressions to extract two numbers (defined as 'f' and 's') from a column, do arithmetic on them, and then define the results of the math as 'newpercent.' This lets me use it further down the template.
Code:
f = re($#chapters, '(.*)/.*', '\1');
s = re($#chapters, '.*/(.*)', '\1');
newpercent = round(multiply ((f / s), 100));
GPM if-then templates:
Code:
if "^Fallout$" inlist f then 'fallout.png:' fi
This is an if-then template.
If 'Fallout' is found in the list f,
then output 'fallout.png:' and
finish.
You can also throw elses in there:
Code:
if "^Fallout$" inlist f then 'fallout.png:' else 'null.png' fi
Here, if 'Fallout' is found, it'll output 'fallout.png'; otherwise, it'll output 'null.png:' and then finish.
Concatenation:
You notice that all the if-then templates are wrapped in a strcat() and that there's a comma at the end of each one.
This means that anything inside it will all be concatenated together. So if I have a book with "Fallout" and "Half-Life" in the column, instead of only displaying the first one, it'll output "fallout.png:halflife.png:" (and display both of them).