The switch tag in the ThinkPHP template is used to output different values in the template according to different situations.
ThinkPHP template engine supports switch judgment and can output different results according to different conditions. The usage format is as follows:
<switch name="变量名" > <case value="值1">输出内容1</case> <case value="值2">输出内容2</case> <default />默认情况 </switch>
Usage examples are as follows:
<switch name="uid"> <case value="1">管理员</case> <default />游客 </switch>
Note here:
The name attribute can use functions and system variables. Its attribute value is the variable name without the $ symbol, while the value value needs the $ symbol when using a variable, as shown in the example above.
When the value of value is used in variable mode, it no longer supports the simultaneous judgment of multiple conditions , such as the following multi-condition judgment.
Multi-condition judgment:
The value attribute of case can support the simultaneous judgment of multiple conditions and use the | symbol to separate:
<switch name="Think.get.type"> <case value="gif|png|jpeg">图像格式文件</case> <default />其他格式文件 </switch>
This means that if the value of $_GET["type"] is gif, png or jpg, it will be judged as an image format.
The name attribute can also be a system variable, and the function can be used, such as:
<switch name="Think.get.username|function1"> ...... </switch>