Skip to content

user elements variables logic

Tim Stair edited this page Sep 18, 2015 · 4 revisions

User Guides - References - Defines

General

This guide covers the transtion variables and logic you can use in a Definition. There is a lot of duplication from the manual. Translation variables are specially formatted blocks of text that are translated before rendering to display something else (much like a reference to a column).

Logic / Functions

The following translation functions and logic apply to all types of Elements. The samples below show Text Element output. As with everything be sure to see the manual.

Counter

Format

##x;y;z#

This will translate as follows: x + (current card index * y) with left padded 0's numbering z

Notes

  • The card index is a 0 based value. This can be a bit confusing but is critical to the use of the y value.

Examples

##1;1;0# -- Just a basic counter starting at card index 1 Card 1 Result: 1 Card 33 Result: 33 Card 100 Result: 100

##5;1;3# -- Counter starting at 5, with left padding. Card 1 Result: 005 Card 33 Result: 037 Card 100 Result: 104

##2;2;0# -- Counter starting at 2, and adding 2 per card index. Card 1 Result: 2 Card 33 Result: 66 Card 100 Result: 200

If Statement (see the manual for more details)

Formats

#(if x [logical statement] y then a)#

OR

#(if x [logical statement] y then a else b)#

This will translate based on the success/failure of the logic statement. There are a number of possible logical operators detailed in the manual.

Examples

#(if 1 == 1 then good news!)# Result: good news!

#(if 1 == 2 then bad news!)# Result: ```` (There is no result because 1 does not equal 2.)

++#(if 1 == 2 then bad news!)#++ Result: ++++

The logical statement will result in nothing but the existing text wrapped around it will appear as normal.

++#(if 1 == 2 then bad news! else good news!)#++ Result: ++good news!++

++#(if 1 == then bad news! else good news!)#++ Result: ++good news!++

This logical statement is comparing 1 to an empty string. As they are not equal this will fail to the else value.

Note: If the comparison or results contain the key words: else or then you might run into trouble. Yikes! If you need to do something that really requires that kind of output I recommend investigating the override:[Element name]:variable as a way to override the Definition value of the Element.

If Statement (grouped)

Formats

#(if [x;y;z] [logical statement] [a;b;c] then m)#

OR

#(if [x;y;z] [logical statement] [a;b;c] then m else n)#

This will translate based on the success/failure of the logic statement based on the existence of x, y, or z in the set of a, b, and c. Only one of the values in the first set must exist in the second set to pass. Both sets are unbounded on size. Only the == and != logical operators are supported for this logic. This is a reasonably complex statement to use and is only recommended if you really need it!

Examples

#(if [1;2] == [5;2;6] then good news! else bad news!)# Result: good news!

#(if [1;2] == [5;6;7] then good news! else bad news!)# Result: bad news!

++#(if [1;2] == [5;6;7] then good news!)#++ Result: ++++

Switch Statement (grouped)

Format

#(switch;key;keytocheck1;value1(unbounded repeat: ;keytoCheck;value))#

This will translate to the value associated when the key matches a keytocheck.

Notes

  • Optionally you may specify #default to indicate that if nothing passes to use the value specified with default.

Examples

#(switch;1;1;good news!;2;bad news!)# Result: good news!

#(switch;2;1;good news!;2;bad news!)# Result: bad news!

++#(switch;54;1;good news!;2;bad news!)#++ Result: ++#(switch;54;1;good news!;2;bad news!)#++ Unlike the if statements the result of a unfound item is the raw text (might be something to consider changing in the application!).

#(switch;3;1;good news!;2;bad news!;#default;confused!)# Result: confused!``