Loading...
 

History: Branching

Preview of version: 4

From Tiki 15 onwards, it is possible to include contents of other YAML files in profiles depending on branching logic.

Basic usage


The basic usage is through the use of the !include directive. In YAML, the "!" preceding the string means that that is a directive and some kiind of execution is to happen, returning some kind of output that replaces the directive.

The following is an extremely basic example on how it works:
test.yml
preferences: feature_wysiwyg: - !include wysiwyg.yml 1 eq 1 - !include nonwysiwyg.yml

wysiwyg.yml
feature_wysiwyg: y

nonwysiwyg.yml
feature_wysiwyg: n

Each of the options of YAML files to include for a particular key (in the above case, feature_wysiwyg) is an item in a list starting with the !include directive followed by the filename (relative) to the profile, and then a condition comparing 2 values using operators.

If the condition is true, then it includes that YAML file and ignores the other conditions. If not it moves on to the next option and performs the test again. It is customary to provide a default YML file in case any of the preceding conditions are not met. This works pretty much is the same way as a typical CASE structure in PHP.

In the above example, wysiwyg.yml will be included and therefore wysiwyg will be on. If on the other hand:
preferences: feature_wysiwyg: - !include wysiwyg.yml 1 eq 2 - !include nonwysiwyg.yml

since 1 not equals 2, it will default to the nonwysiwyg.yml and set feature_wysiwyg to 'n'.

Note that the contents of the included YAML files should start with the same key as that to be replaced. For example, wysiwyg.yml and nonwysiwyg.yml both start with "feature_wysiwyg".

Comparison operators

eq: equal to
neq: not equal to
lt: less than
le: less than or equal to
gt: greater than
ge: greater than or equal to

History

Advanced
Information Version
Wed 25 of Nov, 2020 12:34 GMT-0000 Jonny Bradley Added some aliases to help searching 14
Wed 04 of Dec, 2019 21:28 GMT-0000 luciash d' being 🧙 formatting 13
Wed 04 of Dec, 2019 18:51 GMT-0000 luciash d' being 🧙 highlight code 12
Wed 04 of Dec, 2019 18:49 GMT-0000 luciash d' being 🧙 Code Plugin modified by editor. 11
Tue 27 of Oct, 2015 23:36 GMT-0000 Nelson Ko add example 10
Tue 27 of Oct, 2015 19:29 GMT-0000 Nelson Ko fix typo 9
Tue 27 of Oct, 2015 19:28 GMT-0000 Nelson Ko example checking prefs 8
Tue 27 of Oct, 2015 19:02 GMT-0000 Nelson Ko mor elimitations 7
Tue 27 of Oct, 2015 19:01 GMT-0000 Nelson Ko add limitations 6
Tue 27 of Oct, 2015 18:49 GMT-0000 Nelson Ko fix brackets 5
Tue 27 of Oct, 2015 18:48 GMT-0000 Nelson Ko change heading 4
Tue 27 of Oct, 2015 18:47 GMT-0000 Nelson Ko mode documentation 3
Tue 27 of Oct, 2015 15:50 GMT-0000 Nelson Ko Some editing 2
Tue 27 of Oct, 2015 15:47 GMT-0000 Nelson Ko Create new Branching page 1