ede icon indicating copy to clipboard operation
ede copied to clipboard

Nested variable as argument to filter is reversed

Open brendanhay opened this issue 10 years ago • 2 comments

Example:

{{ field.value.name | justifyRight(field.value.indent) }} :: {{ field.value.type }}

Error:

error: variable indent.value.field doesn't exist.

brendanhay avatar Nov 01 '14 14:11 brendanhay

Is that still an issue? I cannot reproduce it... JSON context used:

{"field": {"value": {"name": "FieldName", "indent": 20, "type": "FieldType"}}}

mmhat avatar Aug 21 '18 18:08 mmhat

I also have a problem with variables in filter arguments, which seems different but perhaps is related.

Take this template, where match is a filter that matches the input to a regex and returns an object with a boolean field ok if the match worked, and a series of fields b0, b1, ... for each capturing group. Also, ifelse is a function that returns the first argument if the input is true, the second otherwise:

{% let X = description | match(", (.+) ([0-9]+\\.[0-9]+) per CHF ([0-9]+\\.[0-9]+)") %}
{% let Y = { "ok": true, "g0": "ciao" } %}
  category                     {% if X.ok %} {{X.g0}} {% else %} {{currency}} {% endif %}
  {{ X | show }}
  {{ Y | show }}
{{ Y.ok | ifelse(Y.g0, 1) }}
{% endlet %}
{% endlet %}

Both show print an object with ok and g0, and everything works. However, if I replace ifelse(X.g0, 1) for ifelse(Y.g0, 1) I get the error

variable X.g0 doesn't exist

mredaelli avatar Feb 24 '19 17:02 mredaelli