<{if Empty ($history)}><tr> <td colspan= "6" >not any records!</td> </tr><{else}> <{foreach from= $history item=item}><tr> <td><{$item .id}></td> <td> <div style= "Max-width:700px;overflow:hidden;text -overflow:ellipsis; "> <a href=" # "> keywords:<{$item .keywords}><br> size:<{$item. SizE}><br><{foreach from=$item. Options Key=key item=option}> <{$key}>:<{$option}><br><{/foreach}></td> <td><{$item .num}></td> <td><{$item .create_time}></td> <td><{$item. Last_Process}></td> <td> <spanclass="label <{if $item. Status eq ' new '}> label-primary <{else}> label-success <{/if}>"> <{$item. status}> </span> </td> <td> <a href= "#"class= "btn btn-danger btn-xs" ><i class= "fa fa-trash-o" ></i>Delete</a> <a href= "#" Clas s= "btn btn-primary btn-xs" ><i class= "FAFa-file-text "></i>Report</a> </td> </tr><{/foreach}><{/if}>
This is an example of the smarty I used in project development, so I withheld it for record. The following are the explanations:
Divided into four colors, corresponding to two statements (Ifelse,foreach), where $history is a two-dimensional array:
1, Yellow green, orange, if Else statement use, and empty () function, the use of EQ
2, blue, red, the use of the foreach statement, where the From and item must be two parameters, from the array to iterate through, the item is the variable name of the current element. There are also two parameters, name and Key,name, which are used to access the variable name of the Foreach loop of the Foreach property, and key is the key value name for the element in the array.
Smarty in IfElse, foreach, and getting an instance of a key value name in an array