Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/matiasperrone/html_options_gi

html_options_gi - Smarty plugin as alternative of html_options - Prints the list of <option> tags generated from a numeric / asociative array
https://github.com/matiasperrone/html_options_gi

Last synced: about 2 months ago
JSON representation

html_options_gi - Smarty plugin as alternative of html_options - Prints the list of <option> tags generated from a numeric / asociative array

Awesome Lists containing this project

README

        

html_options_gi - version 1.1
=============================

html_options_gi is a smarty plugin as alternative of html_options.

Prints the list of <option> tags generated from a numeric / asociative array.

Parameters:
===========

options (required) - associative array.
values (required) - The key of the options array for the value in OPTION element.
output (required) - The key of the options array for the text in OPTION element.
selected (optional) - string or array (multiple selects), used to mark as "selected" the options.
name (optional) - If this parameter is set then creates a SELECT element with this name.
id (optional) - string default not set, used only if name is not empty.
class (optional) - string default not set, used only if name is not empty.
????? (optional) - string parameter added to the SELECT element.
data (optional) - string of JSON encoding of an object of "name": "field" used to add as "data-name" to the OPTION elements and populating with the value of "field".

Examples
========

Example of "currency" table as:


currency_idcurrency_signcurrency_isocurrency_name


1$ARSPesos ARS


2u$sUSDUS Dolars


3€EUREurs

Using PHP:
```php
// Assuming $smarty and $db already initialized
$result = mysqli_query($db, "SELECT * FROM currency") or die();
$data = array();
while ($row = mysqli_fetch_assoc($result))
$data[] = $row;
$smarty->assingByRef('data', $data);
```

## Example 1:
```html

[Select a Currency]
{html_options_gi values="currency_id" output="currency_name" options=$data}

```

### Result:
```html

[Select a Currency]
Pesos ARS
US Dolars
Eurs

```

## Example 2:
if "Select a Currency" is not necessary, and adding "style" as a parameter:
```html
{html_options_gi name="currency" id="currency" values="currency_id" output="currency_name" options=$data style="width: 67%; height: 30px; float: right;"}
```

### Result:
```html

Pesos ARS
US Dolars
Eurs

```

Example 3:
==========
if "Select a Currency" is not necessary, and adding "style" as a parameter and a "data" parameter:
```html
{html_options_gi name="currency" id="currency" values="currency_id" output="currency_name" options=$data style="width: 67%; height: 30px; float: right;" data='{"iso":"currency_iso"}'}
```

### Result:
```html

Pesos ARS
US Dolars
Eurs

```