Filter
Template Tag Filter
-
Determine if the text, array contains a specified keyword
How to judge whether a line of text string contains a certain keyword in AnQi CMS template?The contain filter can determine if a keyword is included in a line of string, array (slice), key-value pair (map), or structure (struct), and the result will return a boolean value (bool).How to use the contain filter: {{obj|contain:keyword -
Remove all leading and trailing spaces and specific characters from a string
How to remove leading and trailing spaces or specific characters from a string in the AnQi CMS template?The trim, trimLeft, trimRight filters can respectively remove spaces at the beginning and end of a string, or specific characters.The trim filter can remove whitespace or specific characters from the beginning and end of a string;The trimLeft filter can remove leading spaces or specific characters from a string;The trimRight filter can remove strings -
Count the occurrences of a specific keyword in a line string and in an array
How to calculate the number of times a keyword appears in a string or array in AnQi CMS template?The count filter can calculate the number of times a keyword appears in a string or array (array/slice).How to use the count filter: {{obj|count:keyword}} For example, calculate the occurrence of CMS in Welcome to AnQiCMS (AnQiCMS) -
Filter: Split a line of text into an array by spaces
How to split a line of text into an array in Anqi CMS template?The fields filter can split a line of text into an array in the template.The defined array is a []string{}, it can be traversed and outputted later.Usage of the fields filter: {% set values = "text content"|fields %} {% set v -
Get the position of a keyword in a line string or array
How to get the position of a keyword in a string or array in Anqi CMS template?The index filter can calculate the position of a keyword in a line of string or array (array/slice).If a string contains multiple keywords to be searched, then index returns the position of the first occurrence.If not found, return -1. Note: when calculating the position of the string, if there is Chinese in the string, -
Define an array in a template
How to define an array in Anqi CMS template? The list filter can define an array in the template.The defined array is a []string{}, it can be traversed and outputted later.Usage of list filter: {% set values = '["keyword1","keyword2","keyword3"]'|list %} Use single or double quotes for the string to be converted -
Replace a specific keyword in a string with another keyword
How to replace a word in a string in Anqi CMS template?The replace filter can replace the old word with the new word in a string and return the new string.If old is empty, it will match at the beginning of the string and after each UTF-8 sequence.If new is empty, remove old. Usage of replace filter: # Replace the old -
Repeat a string multiple times
How to repeat a string a specified number of times in Anqi CMS template?The repeat filter can repeat a string a specified number of times.How to use the repeat filter: {{obj|repeat:times}} For example, to repeat "AnQiCMS" 5 times, you can write: {{"AnQiCMS"|repeat:5}} # Display result AnQiCMSAnQiCMS -
Add numbers or strings
Filter: Add numbers or strings -
Add a backslash before predefined characters
How do I add a backslash before predefined characters in a string in AnQi CMS template?The addslashes filter adds a backslash before predefined characters.These characters are single quotes (') and double quotes (") and backslashes (\).How to use the addslashes filter: {{ obj|addslashes }} For example, to escape the predefined characters in 安企\"CMS\" -
Convert English string characters to uppercase or lowercase
How to convert English string letters to uppercase or lowercase in AnQi CMS template?The capfirst filter can capitalize the first letter of an English string.Only alphabetic characters will be converted. The lower filter can convert all letters in a string to lowercase.The upper filter can convert all letters in a string to uppercase.title The filter can remove all the words from the English string -
Display the string centered, left-aligned, or right-aligned according to a specified length
How to display a string centered, left-aligned, or right-aligned in a specified length in AnQi CMS template?The center filter can display strings centered according to a specified length.If the length of the string is greater than the specified length, it will be displayed according to the actual length of the string. If the length of the string is less than the specified length, an equal number of spaces will be added on both sides of the string to achieve centering.If the number of spaces to be added is odd, then the spaces on the right will be more than -
Remove the specified character from any position in the string
How to remove a specified character from a string at any position in the Anqi CMS template?The cut filter can remove specified characters from any position in a string.As removing special characters, spaces, and other operations, all can use the cut filter method: The usage method of the cut filter: {{ obj|cut:"keyword" }} For example, to remove the letter s from test, it can be written like this: {{ "test"|cu -
Display time value in a specified format
How to display time values in a specified format in Anqi CMS template?The date filter can display time values in a specified format.But note that the input of date must be a time.Time value, otherwise it cannot be processed and an error will occur.The output format is set according to the Golang time format.You can also use time, it has the same usage and result as date.It is the alias of date -
Set default values for numbers, strings, or objects
How to set default values for numbers or strings, objects if they do not have values in AnQi CMS template?The default filter can set a default value for numbers or strings if a number or string, or an object does not have a value.The default_if_none filter can determine if a pointer type object is empty, and if it is empty, it sets a default value.How to use the default filter method: { -
Determine if a number can be used as a divisor
How to judge whether a number or its calculation result can be used as a divisor in the Anqi CMS template?The divisibleby filter can determine if a number or its calculation result can be used as a divisor.The filter will return a boolean value (bool), True means yes, False means no.The usage of the divisibleby filter: {{ number| -
Escape special characters in strings and JavaScript code
How to escape special characters such as HTML code in strings and JavaScript code in AnQi CMS templates?The escape filter can escape special characters in a string.For example, output HTML code for display instead of parsing HTML code.As for, &,' and "., it will be converted to >., & will be converted to &, " will be converted to ", ' will be converted to '. Also can make -
Split a line of text into an array by spaces
How to split a line of text into an array in Anqi CMS template?The fields filter can split a line of text into an array in the template.The defined array is a []string{}, it can be traversed and outputted later.Usage of the fields filter: {% set values = "text content"|fields %} {% set v -
The first or last value of a string or array
How to get the first or last value of a string or array in Anqi CMS template?The first filter can get the first character of a string or the first value of an array.If the original string or array is empty, do not return anything. If the string is Chinese, return the first Chinese character.The last filter can get the last character of a string or the last value of an array.If the original string or array is empty, do not return anything. If the string is -
Keep floating-point numbers to a certain number of decimal places
How to output a floating-point number with 2 decimal places in AnQi CMS template?The floatformat filter can output a floating-point number with 2 decimal places.Also, you can retain decimal points with specified digits. For example, retaining 3 decimal places, etc.Supports negative number of digits, if a negative number is set, it calculates from the last digit upwards.The usage of floatformat filter: {{ obj|float -
Get the specified position of the number in the number
How to get a number at a specified position in an Anqi CMS template?The get_digit filter can obtain the digit at a specified position in a number, with the position counted from the end of the number, starting from 1.If the position to be obtained does not exist, return the entire number.If the original number is a number, then the result obtained is the number obtained by subtracting 48 from the ASCII value of the character at that position.Use method get_digit -
Convert a numeric string to a float or integer
How to convert a numeric string to a floating-point number or integer in AnQi CMS template?The float filter can convert a numeric string to a floating-point number.If the conversion fails, it will return 0.0. The integer filter can convert a string to an integer.If the conversion fails, return 0. Usage method of float filter: {{ obj|float }} Usage method of integer filter: -
Concatenate an array into a string with a specified separator
How to concatenate an array into a string with a specified delimiter in Anqi CMS template?The join filter can concatenate the values of an array into a new string with a specified separator.If the original object is a string, it will directly concatenate the characters with a concatenation symbol.How to use the join filter: {{ obj|join:":delimiter" }} For example, you need to join ["splits", "the -
Get the length of a string, array, or key-value pair
How to get the length of a string, array, and key-value pair in Anqi CMS template?The length filter can get the length of strings, arrays, and key-value pairs.For a string, it calculates the actual character count of utf8, one letter is one, and one Chinese character is also one.The array and key-value pairs can be used to calculate their index count. You can also use length_is to calculate the length while comparing it with the input length and -
Convert multiline text to HTML tags with line breaks
How to convert multiline text to HTML tags in the Anqi CMS template?The linebreaks filter can convert multi-line text to HTML tags by line breaks.Enclosed with and at the beginning and end of each line, use . for empty lines.You can still use linebreaksbr to process it.The difference with linebreaks is that linebreaksbr simply converts line breaks -
Convert letters on the mobile phone keypad to numbers
How to convert letters on the mobile phone number keypad to numbers in AnQi CMS template?The phone2numeric filter can convert letters on the phone number keypad to numbers.Conversion relationship is: { "a": "2", "b": "2", "c": "2", "d": "3", "e": "3", "f": "3", "g": "4", "h": "4", "i -
Plural form of a word
How to convert a word to plural form based on quantity in AnQi CMS template?The pluralize filter can convert a word to its plural form based on the quantity.The usage of the pluralize filter: {{ obj|pluralize:"plural suffix" }} pluralize requires specifying the current number and adding the plural word.Supports 0 to 2 words, use two words when necessary -
Return a random character, value from a string or array
How to return a random character from a string, array, value in AnQi CMS template?The random filter can return a random character or value from a string, array.Usage of the random filter: How to use {{ obj|random }} For example, to return any value from [1,2,3,4,5], you can write: {{ "1,2,3,4,5"|split -
Remove HTML tags from HTML code
How to remove tags from HTML code in AnQi CMS template?The striptags filter can remove all HTML tags from the HTML code.removetags filter can remove specified tags from html code.How to use the striptags filter: {{ obj|striptags }} removetags filter usage -
Parse HTML code and output without escaping
How to parse HTML code without escaping in Anqi CMS template?The safe filter can disable the default escaping attribute of template output, allowing direct output of HTML code to the interface for the browser to parse the HTML code.Generally used in rich text output, such as displaying article details and the like.Note: Use the safe filter, it is assumed by default that your output is safe, it will not escape special characters, so if you want to replace -
Extract elements from a string or array at specified positions
How to extract a string, and elements from an array at specified positions in Anqi CMS template?The slice filter can extract elements from a string or an array at specified positions.For example, get the third to the seventh elements of an array with 10 elements.Usage of slice filter: Usage method: {{obj|slice:"from:to"}} Note that from and to are separated by :.like return [1, -
Split a string into an array using a specified delimiter
How to split a string with a specific format into an array in AnQi CMS template?The split filter can split a string of a specific format into an array using a specified delimiter.If the delimiter is not present in the string, it will return an array of length 1, with the value being the string itself.If the delimiter is empty, it will split into an array by each UTF-8 character.You can also use make_list to quickly split strings -
Format any value to a string output
How to format numbers, strings, arrays, and other arbitrary values into strings with a specified format in Anqi CMS template?The stringformat filter can format numbers, strings, arrays, and any other values into a string output according to a specified format.Some formatting standards: %v Output structure {10 30}%+v Output structure display field names {one:10 tow:30}%#v Output structure source -
Truncate strings or HTML code and add...
How to cut and add ... to strings or HTML code in Anqi CMS template?The truncatechars filter can truncate strings and add... This method will truncate words, including the specified length...The truncatechars_html filter can truncate HTML code and add... The method will truncate words, including the specified length... trun -
URL parameter escaping
How to escape URL parameters in AnQi CMS template?The urlencode filter can escape URL parameters.The iriencode filter can escape URL parameters, except for /#%[]=:;All other characters outside of the URL-encoded characters will be encoded in the URL parameter encoding format.The usage method of the urlencode filter: {{ o -
Find and parse the URL string in the text into a clickable a tag
How to find and parse the URL strings in the text into clickable a tags in the Anqi CMS template?The urlize filter can find and convert URL strings in text to clickable a tags.The urlizetrunc filter can find and parse URL strings in text into clickable a tags, and can specify the text displayed in the a tag to be truncated to a specified length.How to use urlize over -
Calculate the number of words in a string
How to calculate the number of words in a string in Anqi CMS template?The wordcount filter can calculate the number of words in a string.The word count will be distinguished by spaces. If it does not contain spaces, it is counted as a word.Returns an integer. Usage of the wordcount filter: {{ obj|wordcount }} Example demonstration{{ ""|wordco -
Automatic line break for long text
How do I make long text automatically wrap to a specified length in Anqi CMS template?The wordwrap filter can automatically wrap long text to a specified length.The wordwrap divides words by spaces. If there are no spaces, it is considered as one word.Therefore if Chinese characters are continuous, they will not be wrapped in a new line. Usage of the wordwrap filter: {{ obj|wordwrap:numbe -
Three states of OR and NOT
How to judge or with and non three states in Anqi CMS template?The yesno filter can be in or, non, and three states. The default values of yesno are 'yes', 'no', and 'maybe'.You can also define these three values as others. When the value is false, return no, when the value is true, return yes, when the value is nil, return maybe. Use -
dump filter: print the structure type and value of the variable
How to view the structure type of variables in Anqi CMS template?The dump filter can print the structure, type, and value of a variable.How to use the dump filter: {{ obj|dump }}For example, to view the structure of bannerItem, you can write: {{ item|dump }}# Display result&config.BannerItem{Logo:"http://127.0.0.1"} -
filter: convert the variable to JSON output
How to convert a variable to JSON output in Anqi CMS template?The filter can convert a variable to JSON output. -
filter: render Markdown content to HTML
How to render a variable as HTML in the Anqi CMS template?The render filter can render a variable into HTML. -
Filter: Get image thumbnail
How to get the thumbnail of the image in Anqi CMS template? thumb The filter can retrieve a thumbnail from the image address.