User Tools

Site Tools


developers:templates:reference

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
Next revision Both sides next revision
developers:templates:reference [2014/10/18 12:48]
Jaco van Wyk
developers:templates:reference [2014/10/18 12:50]
Jaco van Wyk [Final Details]
Line 35: Line 35:
 Some variables hold values that we might want to be formatted according to a set of rules. For instance if we had $date with today’s date in it, putting it in the template would write “2011-01-14 14:​03:​35″. While sometimes that’s what we want, sometimes you would want to write it as “January 14th”, and sometimes as “14 Jan, 2:03pm”. In order to allow for all of these options we have a formatting option for variables. Some variables hold values that we might want to be formatted according to a set of rules. For instance if we had $date with today’s date in it, putting it in the template would write “2011-01-14 14:​03:​35″. While sometimes that’s what we want, sometimes you would want to write it as “January 14th”, and sometimes as “14 Jan, 2:03pm”. In order to allow for all of these options we have a formatting option for variables.
  
-In order to format a variable, simply put parenthesis straight after the variable without any spaces. Each variable is formatted differently,​ according to its type. A date variable is formatted according to the [[PHP date function|http://​php.net/​manual/​en/​function.date.php]] so “$date(F jS)” would write out “January 14th”. Most other variables are formatted according to [[printf formatting|http://​en.wikipedia.org/​wiki/​Printf#​Format_placeholders]].+In order to format a variable, simply put parenthesis straight after the variable without any spaces. Each variable is formatted differently,​ according to its type. A date variable is formatted according to the [[http://​php.net/​manual/​en/​function.date.php|PHP date function]] so “$date(F jS)” would write out “January 14th”. Most other variables are formatted according to [[http://​en.wikipedia.org/​wiki/​Printf#​Format_placeholders|printf formatting]].
  
 Some variables can even be formatted according to other variables. This is the case you would generally use with formatting according to currency. If you have the client credit of 14.65 in $credit you would simply call “$credit($client->​currency)” which would then print out R14.65 if your client is using South African Rands :) . Some variables can even be formatted according to other variables. This is the case you would generally use with formatting according to currency. If you have the client credit of 14.65 in $credit you would simply call “$credit($client->​currency)” which would then print out R14.65 if your client is using South African Rands :) .
Line 78: Line 78:
 Variables can also be formatted according to a bunch of specific rules. In order to pass the variable to be formatted the code looks like $username(>​upper) which will pass the username to the ‘upper’ function (will look something like “JOSH”). The complete list of current functions available is: upper (upper-case),​ lower (lower-case),​ u2s (underscores to spaces), ucwords (upper-case first letter of each word), ucfirst (upper-case only first letter), and empty (coverts to nothing – which is sometimes useful when combined with the missing variable syntax). Variables can also be formatted according to a bunch of specific rules. In order to pass the variable to be formatted the code looks like $username(>​upper) which will pass the username to the ‘upper’ function (will look something like “JOSH”). The complete list of current functions available is: upper (upper-case),​ lower (lower-case),​ u2s (underscores to spaces), ucwords (upper-case first letter of each word), ucfirst (upper-case only first letter), and empty (coverts to nothing – which is sometimes useful when combined with the missing variable syntax).
  
-The ternary operator is also available as a formatting function. We use the C syntax with <​test>​ ? <if true> : <if false>. If the <if true> section is not specified it defaults to being the same as the <​test>​. This is all most easily demonstrated with sample code.+The [[http://​en.wikipedia.org/​wiki/​Ternary_operation|ternary operator]] is also available as a formatting function. We use the C syntax with <​test>​ ? <if true> : <if false>. If the <if true> section is not specified it defaults to being the same as the <​test>​. This is all most easily demonstrated with sample code.
  
 <​code>​ <​code>​
developers/templates/reference.txt · Last modified: 2019/05/10 07:30 by Jaco van Wyk