• 
      

    Add a as_type= argument for {% definevar %} for casting to types.

    Review Request #14698 — Created Nov. 18, 2025 and submitted — Latest diff uploaded

    Information

    Djblets
    release-5.x

    Reviewers

    {% definevar %} can now store a value as a boolean or integer through
    the as_type= argument. By default, this stored as a string
    (equivalent to str).

    When passing as_type=bool, a true (lowercased) or 1 will
    result in a stored True. Anything else will be False.

    When passing as_type=int, the value will be converted to an integer.
    If the value can't be parsed as an integer, a TemplateSyntaxError will
    be raised.

    There's also an optimization around the options. We now convert to a
    set so 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.

    Commits

    Files