Modifiers functions

As it has been explained before in the variables tag, modifiers are functions that modify the variable value before printing it and you can write your own modifier function to use within the blocks by following these steps:

  • Create a file within the 'include/modifiers' folder using this name form 'modifier.name.php' where 'name' is the function name.
  • Write the following function formula in the function file:

function Dimofinf_modifier_name($params)

[code] function Dimofinf_modifier_name($params) { $string = $params['string']; // the code return $string; } [/code]

Where 'name' is the function name and '$params' is a matrix that includes the function parameters which are called when the modifier is called from within the block as every entry takes an index in the '$params' matrix and its value is the inserted value and it also includes the 'String' index which contains the variable value, noting that the function should return a value at the end where '$val' is an example for the reference value from the function. Please note that modifiers can be called several times for the same variable simultaneously.

      Helping modifiers which can be used in the blocks:

These are some useful modifiers which can help you with your programming and blocks:

      {var|calc values="5,5,8" sign="+"}

This modifier is used to perform mathematical operations on the variable 'var' value.

 

Parameters:

  • sign (optional): the operation sign; '+' for addition, '-' for subtraction, '*' for multiplication and '/' for division.
  •  values (mandatory): the values the mathematical operations will be done on.

Example:

CODE :

This modifier will perform the first mathematical operation by adding '5+5+8' then it will perform the second operation by multiplying the result of the first operation by '1'.

      {string|default value="value"}

This modifier is used to assign the default value in case the 'string' value is empty.

Parameters:

  • value (mandatory): the default value that will be assigned if the main variable value is empty.

Example:

CODE :

      {string|replace values="value_before,value_after"}

This modifier is used to replace words from the 'string' variable value.

Parameters:

  • values (mandatory): includes the value you want to replace and the word you want to replace it with; these two are separated by a comma.

Example:

CODE :

      {string|wordwrap length="90" break="n" cut="true"}

This modifier is used to break the sentence after a certain number of characters where the function 'wordwrap' is called from PHP.

Parameters:

  • length (mandatory): the number of characters after which the sentence is broken; moves to the next line.
  • break (optional): the division separator, it is '/n' by default.
  • cut (optional):when this is assigned to 'true', the division/breaking is forced. In other words, if you have a word is 8 characters and you set the sentence break at 4 characters, the word will be forced to break after 4 characters and won't be excluded because it is a connected word.

Example:

CODE :

Was this answer helpful? 0 Users Found This Useful (0 Votes)