Smarty in IfElse, foreach, and getting an instance of a key value name in an array

Source: Internet
Author: User

<{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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.