Enabled performing mathematical operations in templates using layout:set:math
tag, :math
variable modifier and exp:math
module
#4414
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Enabled performing mathematical operations in templates using layout:set:math tag
Added :math modifiers on variables and exp:math module
This PR is allowing to perform mathematical operations prior to assigning the result to layout variable. To achieve that, use
{layout:set:math}
tagThe following code will produce something like
1409.24202
Under the hood, it's using EvalMath library, which is the same one that mx_calc is using.
Another two options are using variable modifier and module
Variable modifier takes the variable (e.g. segment_1) as first part of expression and optional
expression
parameter as its second part. Additionally,function
can be applied to the result. So if we want to divide to entry date by by 10, add 5 to the result and then take square root of it we can do the followingModule tag works the same as variable modifier, but it expects complete expression. It can be used as single tag as a tag pair. When used as tag pair, the result is in
result
variableBoth modifier and tag return the result formatted. They accept same parameters as
:number_format
modifierThe documentation is here: ExpressionEngine/ExpressionEngine-User-Guide#994