Smarttemplate 1.2.1 official source files can be retrieved fromHttp://download.csdn.net/source/670995Download
The instance code in this series of articles can be used to access my resourcesHttp://download.csdn.net/source/670977Download
I used to learn things in the east and west. Now I have time to learn things, and I also make a record to help you learn smarttemplate, there will inevitably be omissions in this article. If you have any mistakes or different opinions, please contact me.Lxbin544930@163.comI will make corrections in time.
5. dropdown_boxes
[Content] basic/dropdown_boxes.php:
<? Php </P> <p> require_once ".. /config/smarttemplate_basic.cfg.php "; </P> <p> $ page = new smarttemplate('dropdown_boxes.html '); </P> <p> $ Cols = array ('red ', 'green', 'blue'); <br/> $ page-> assign ('colors ', $ Cols ); <br/> $ page-> assign ('default', "blue"); <br/> $ page-> output (); </P> <p >?>
[TEMPLATE] templates/basic/dropdown_boxes.html:
<Form> <br/> <select name = "color"> <br/> {options: colors, default} <br/> </SELECT> <br/> </form>
[Return]
<Form> <br/> <select name = "color"> <br/> <option> Red </option> <br/> <option> green </option> <br/> <option selected = "selected"> blue </option> </P> <p> </SELECT> <br/> </form>
【]
[Note]
This is an example of using the option label in the template, only select items with no value, such as <option> Option 1 </option> <option> Option 2 </option>, the example with the value attribute is in the extended function folder [extensions/options. PHP].
In the smarttemplate template, {options: colors, default} is used to represent the select option set <option>, in the corresponding PHP processing file, the corresponding array variable $ Cols should be assigned to colors through $ page-> assign ('colors ', $ Cols); in fact, the template class is {options: colors, default} resolved to smarttemplate_extension_options ($ Param, $Default= 'Blue '), simply put,' {extended function item: 'is parsed into 'function smarttemplate_extension _ extended function item (' and the value following the colon as the parameter item of the corresponding function. Every time I paste the code of related functions in the appendix, this will help us understand the use of template-related functions more quickly and more accurately, while saving the obscure explanation.
[Appendix]
Include/smarttemplate_extensions/smarttemplate_extension_options.php PHP code. I have made some modifications to the following code, and the comments are the original code (I will not explain it for your reference only for your convenience)
<? Php </P> <p>/** <br/> * smarttemplate extension options <br/> * creates HTML dropdown Option List from an array <br/> * <br/> * usage example I: <br/> * content: $ template-> assign ('pick', array ("on", "off"); <br/> * template: choose: <select name = "Onoff"> {options: Pick} </SELECT> <br/> * result: choose: <select name = "Onoff"> <option> On </option> <option> off </option> </SELECT> <br/> * usage example I I: <br/> * content: $ template-> assign ('color', array ("ff0000" => "red", "00ff00" => "green ", "0000ff" => "blue"); <br/> * $ template-> assign ('default', "00ff00"); <br/> * template: color: <select name = "col"> {options: color, default} </SELECT> <br/> * result: color: <select name = "col"> <option value = "ff0000"> Red </option> <option value = "00ff00" selected> green </option> <option value =" 0000ff "> blue </optio N> </SELECT> <br/> * @ author Philipp v. criegern philipp@criegern.com <br/> */<br/> function smarttemplate_extension_options ($ Param, $ default = '_ default _') <br/>{< br/> $ output = ""; <br/> If (is_array ($ PARAM )) <br/>{< br/> $ keyindex = 0; <br/> foreach ($ Param as $ key => $ value) <br/>{< br/> if ($ key = $ keyindex ++ & is_numeric ($ key )) <br/>{< br/> // $ output. = '<option '. ($ value = $ default )? 'Selected ':''). '> '. $ value. '</option>'; <br/> $ output. = '<option '. ($ value = $ default )? 'Selected = "selected "':''). '> '. $ value. '</option> '. "/N"; <br/>}< br/> else <br/> {<br/> // $ output. = '<option value = "'. $ key. '"'. ($ key = $ default )? 'Selected ':''). '> '. $ value. '</option>'; <br/> $ output. = '<option value = "'. $ key. '"'. ($ key = $ default )? 'Selected = "selected "':''). '> '. $ value. '</option> '. "/N"; <br/>}< br/> return $ output; <br/>}</P> <p >?>