Syntax usage " | "

{{ states.input_slider.slider2.state | int }}

I see a lot of code like this. Where is the documentation explaining what " | int "
means and how to properly use it. Is this a way of casting a variable to a specific type?

Thanks,

1 Like

The docs for templating are here:

Which point to the jinja documenation, and specifically the explanation of the integer option.

http://jinja.pocoo.org/docs/dev/templates/#int

edit: see also

filters: http://jinja.pocoo.org/docs/dev/templates/#filters

1 Like

so, when using the filter with numerical types (float , int ). Would this work the same as casting?

In the previous example {{ states.input_slider.slider2.state | int }}
would this cast whatever is in {{ states.input_slider.slider2.state}} to an integer value?

Thanks,

Here is the definition of the int filter in the documentation that @silvrr provided above:

int(value, default=0, base=10)¶
Convert the value into an integer. If the conversion doesn’t work it will return 0. You can override this default using the first parameter. You can also override the default base (10) in the second parameter, which handles input with prefixes such as 0b, 0o and 0x for bases 2, 8 and 16 respectively. The base is ignored for decimal numbers and non-string values.

1 Like