Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:documentation:how_to:use:placeholder [2018/12/04 09:45]
Côme Chilliet [Modifiers]
— (current)
Line 1: Line 1:
-===== Placeholder ===== 
- 
-You can use placeholders to automate the insertion of some fields in template. 
- 
-===== How can use it =====  
- 
-Placeholder must always be enclosed in %.  
- 
-<​code>​ %sn%           The value of "Last name" field, entered during account creation.</​code> ​ 
- 
-==== Modifiers ==== 
- 
-Modifiers can be used to generate //​something//​ from others parameters. You can use it individually or in combination. 
- 
-=== s === 
- 
-The modifier **s** can be used to generate **s**ubstrings. The following are few examples using %sn% : 
- 
-<​code>​ %s[1,​3]|sn% ​          a substring of "Last name" field, taking 3 characters and starting at position 1. 
- ​%s[0,​1]|sn% ​          the first character of "Last name" field. 
- ​%s[1]|sn% ​            the first character of "Last name" field (short syntax). 
- ​%s[5]|sn% ​            a substring of "Last name" field, taking 5 first characters. 
- ​%s[2,​4-8]|sn% ​        a substring of "Last name" field, taking minimum 4 characters (more if needed for unicity) ​ 
-                       and starting at position 2. 
- ​%s[4-8]|sn% ​          a substring of "Last name" field, taking minimum 4 characters (more if needed for unicity). 
- ​%s[-5,​2]|sn% ​         a substring of "Last name" field, taking 2 characters and starting 5 characters from the end. 
- ​%s[-5,​5]|sn% ​         a substring of "Last name" field, taking the last 5 characters. 
-</​code>​ 
- 
-=== p === 
- 
-The modifier **p** can be used to remove whites**p**aces. ​ 
-Starting with FD 1.1, it can also be used for any search and replace based on **p**reg_replace. For this provide 2 arguments, first one is regexp, second one is replacement string. 
-Default values are /\s/ and empty string, to remove all whitespaces as in previous behavior. 
- 
-Examples using %sn%: 
- 
-<​code>​ 
- ​%p|sn% ​          "​Last name" field, without whitespaces. "O Connor"​ becomes "​OConnor"​. 
- ​%p[/​\s/,​-]|sn% ​  "​Last name" field, with whitespaces replaced by dashes. "O Connor"​ becomes "​O-Connor"​.</​code> ​ 
-=== u === 
- 
-The modifier **u** can be used to return the **u**ppercase version of the parameter. An example using %sn% : 
- 
-<​code>​ %u|sn% ​          "​Last name" field returned in uppercase. ​ 
-                   If "​sn=Valérie"​ then the returned value is "​VALÉRIE"</​code> ​ 
- 
-=== l === 
- 
-The modifier **l** can be used to return the **l**owercase version of the parameter. An example using %sn% : 
- 
-<​code>​ %l|sn% ​          "​Last name" field returned in lowercase. ​ 
-                   If "​sn=Valérie"​ then the returned value is "​valérie"</​code> ​ 
- 
-=== a === 
- 
-The modifier **a** can be used to return the un**a**ccented version of the parameter. An example using %sn% : 
- 
-<​code>​ %a|sn% ​          "​Last name" field returned in unaccented. ​ 
-                   If "​sn=Valérie"​ then the returned value is "​Valerie"</​code> ​ 
- 
-=== t === 
- 
-The modifier **t** can be used to return the **t**ransliterated version of the parameter. ​ 
-The parameters are the list of locales to use for transliteration (first one will be used by non-interactive uses of the template).\\ 
-An example using %sn% : 
- 
-<​code>​ %t[de_DE]|sn% ​          "​Last name" field returned transliterated. 
-                         If "​sn=Süßkartoffel"​ then the returned value is "​Suesskartoffel"</​code> ​ 
- 
-Note that the locale used must be installed on the server (and web server needs to be restarted after locale installation). 
- 
-=== b === 
- 
-The modifier **b** can be used to convert to **b**ase64. 
- 
-=== c === 
- 
-The modifier **c** can be used to put a **c**omment. An example : 
- 
-<​code>​ %c|this is just a comment% ​          ​returns an empty string.</​code> ​ 
-It can also be used to make a template uid unique when 2 templates have the same uid pattern: 
-<​code>​ %al|sn%%c|template1% 
- ​%al|sn%%c|template2%</​code>​ 
- 
-=== r === 
- 
-The modifier **r** can be used to generate **r**andom strings, for instance for passwords.\\ 
-It can take up to three arguments: min length, max length, and character type.\\ 
-Third argument should be either l for letters, d for digits or b for both. Default is both.\\ 
-The default length is 8 and if there is only one argument it will be used as a fixed length. 
- 
-Examples: 
- 
-<​code>​ %r[6,​10]|% ​      a random string with a random length between 6 and 10 chars containing both letters and digits 
- ​%r|% ​            a random string of length 8 
- ​%r[12]|% ​        a random string of length 12 
- ​%r[5,​10,​d]|% ​    a random string of a random length between 5 and 10 containing only digits</​code>​ 
- 
-=== d === 
- 
-The modifier **d** (added in FD 1.1) can be used to generate **d**ates and times.\\ 
-First parameter is date string (defaults to "​now"​),​ second one is date format (defaults to "​d.m.Y",​ to be used in date fields). 
- 
-Examples: 
- 
-<​code>​ 
- ​%d|% ​                             15.03.2017 
- ​%d[tomorrow]|% ​                   16.03.2017 
- ​%d[today+6days]|% ​                ​21.03.2017 
- ​%d[now,​l jS \of F Y h:i:s A]|%    Wednesday 15th of March 2017 02:12:18 PM 
- ​%d[today,​epoch]|% ​                From 1.3 it's possibe to use epoch date format 
-</​code>​ 
- 
-=== n === 
- 
-The modifier **n** (added in FD 1.4) can be used to generate **n**umbers.\\ 
-As the **r** and **d** modifiers it should be used alone, with no attribute name.\\ 
-This modifier will make sure the result value is unique for the filled field in the LDAP. The number will get as high as needed to ensure that.\\ 
-First parameter is whether the number should always be there or only in case of duplicates (1 or 0, defaults to 0). Second parameter is starting number, defaults to 1. Third parameter is step, defaults to 1. 
- 
-Examples: 
- 
-<​code>​ 
- ​%n|% ​          If not unique, adds a number starting at 1 
- ​%n[1]|% ​       A number starting at 1 
- %n[0, 2]|%     If not unique, adds a number starting at 2 
- ​%n[1,​10]|% ​    A number starting at 10 
- ​%n[1,​20,​10]|% ​ A number starting at 20 and going up ten by ten 
-</​code>​ 
- 
-==== Array modifiers ==== 
- 
-Uppercase modifiers can be used to handle array attributes. ​ 
- 
-=== F === 
- 
-The **F** modifier returns the **f**irst value of the array 
- 
-=== L === 
- 
-The **L** modifier returns the **l**ast value of the array 
- 
-=== J === 
- 
-The **J** modifier returns the values **j**oined together. It takes the separator as parameter. 
- 
-<​code>​ %J[:​]|arrayAttribute% ​          ​returns the values joined and separated by : character</​code> ​ 
- 
-=== C === 
- 
-The **C** modifier (added in version 1.0.10) returns the **c**ount of values in the attribute. It can be 0. 
- 
-<​code>​ %C|arrayAttribute% ​          ​returns the number of values in arrayAttribute</​code> ​ 
- 
-==== Combining examples ==== 
- 
-<​code>​ %al|sn% ​          "​Last name" field returned in lowercase unaccented. ​ 
-                    If "​sn=Valérie"​ then the returned value is "​valerie"</​code>​ 
-<​code>​ %au|sn% ​          "​Last name" field returned in uppercase unaccented. ​ 
-                    If "​sn=Valérie"​ then the returned value is "​VALERIE"</​code>​ 
-<​code>​ %alp|sn% ​         "Last name" field returned in lowercase unaccented without whitespaces. ​ 
-                    If "​sn=Valérie DUPONT"​ then the returned value is "​valeriedupont"</​code>​ 
-<​code>​ %us[0,​4]|sn% ​     a substring of "Last name" field, taking 4 characters, starting at position 0 and converting in uppercase. ​ 
-                    If "​sn=Valérie"​ then the returned value is "​VALÉ"​.</​code> ​ 
-<​code>​ %ls[1,​4]|sn% ​     a substring of "Last name" field, taking 4 characters, starting at position 1 and converting in lowercase. ​ 
-                    If "​sn=Valérie"​ then the returned value is "​alér"​.</​code> ​ 
-<​code>​ %las[4]|sn% ​    a substring of "Last name" field, taking the first 4 characters and converting in unaccented lowercase. ​ 
-                    If "​sn=Valérie"​ then the returned value is "​vale"​.</​code> ​ 
-<​code>​ %r[8,​8,​l]u|% ​    a random string of length 8, containing uppercase letters.</​code> ​ 
  
en/documentation/how_to/use/placeholder.1543913143.txt.gz · Last modified: 2018/12/04 09:45 by Côme Chilliet
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0