In Views it is possible to rewrite the output result of a field.
If choosing:
'Override the output of this field with custom text', I can read leading text:
'You may include HTML or Twig. You may enter data from this view as per the "Replacement patterns" below.'
What I need is some simple math, like a division of the actual field. In Twig documentation I have found that both division / and floored division // among other math function is possible in twig. Trying this in Views I do not get the right result.
I have an integer field {{field_ute}} that have 140 as output. When trying maths on it I get these results:
{{field_ute}}=140
{{field_ute/2}}=0.5
{{field_ute//2}}=0
{{field_ute+10}}=11
The math operation is done but the field value are always set to 1 regardless of what the value really are.
What have I done wrong?

Comments

chrotto created an issue. See original summary.

chrotto’s picture

Title: Math in rewrite result in Wiews » Math in rewrite result in Views
cilefen’s picture

Issue tags: -but +Twig
javjaff’s picture

I had the same problem. I'd tried many different variants and filters in "override the output" option.
{{ field_ute|number_format }} seems to be equal 1 (field_ute is the example here).
I got the same results by overriding default views template for fields using {{ field_ute.content }} inside a code.
{{ field_ute.content }} is displayed correctly, but it doesn't want to be used in math.

axel.rutz’s picture

dawehner’s picture

Status: Active » Closed (duplicate)

I would argue its a duplicate of what @alex.rutz linked to. Thank you for finding this url!