In the template development of AnQi CMS, we often need to handle various types of data.Whereas, determining whether a variable is a valid number (either an integer or a floating-point number) for performing corresponding mathematical operations or displaying logic is a common requirement.is_numericThis function, but we can cleverly utilize its built-in filters and logical judgment tags to achieve this goal.

The template language of AnQi CMS is simple and efficient, variables are usually passed through double curly braces{{ 变量名 }}to output, and logical control is used{% 标签名 %}. To determine if a variable is a number, the core is to try to convert it to a numeric type and observe the conversion result.

Core Tools: Number Conversion Filter and Logical Judgment

In the AnQi CMS template, there are several key filters that help us with the conversion of numeric types:

  1. integerFilterAttempt to convert the variable to an integer. If the variable itself is an integer, or a string that can be converted to an integer (such as "123"),