Add a as_type= argument for {% definevar %} for casting to types.
Review Request #14698 — Created Nov. 18, 2025 and updated — Latest diff uploaded
{% definevar %}can now store a value as a boolean or integer through
theas_type=argument. By default, this stored as a string
(equivalent tostr).When passing
as_type=bool, atrue(lowercased) or1will
result in a storedTrue. Anything else will beFalse.When passing
as_type=int, the value will be converted to an integer.
If the value can't be parsed as an integer, aTemplateSyntaxErrorwill
be raised.There's also an optimization around the options. We now convert to a
setso we don't repeatedly iterate through the list for each option.
Unit tests pass.
Made use of this in some in-progress code in Review Board for setting
options.