PHP code example of jbzoo / html
1. Go to this page and download the library: Download jbzoo/html library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jbzoo / html example snippets
// Get needed classes
use JBZoo\Html\Html;
echo Html::_('input')->render( /* ... */ ); // Underscore as factory
$html = Html::getInstance(); // Create or get pimple container
echo $html['input']->render( /* ... */ ); // As array
echo $html->input->render( /* ... */ ); // As object
echo Html::_('button')->render('test', 'Button', array('title' => 'title attr'));
echo Html::_('button')->render('test', 'Button', array(), 'reset');
echo Html::_('button')->render('test', 'My button', array('button' => 'success', 'class' => 'my-class'));
echo Html::_('button')->render('test', 'My button', array('button' => 'success', 'icon' => 'stop'));
echo Html::_('radiobool')->render('show', 0); // 0 is "No" and 1 is "Yes"
echo Html::_('checkbool')->render(
'show', // Name
0, // Checked value
array( // Attrs
'data-rel' => 'tooltip',
'data-title' => 'Checkbox title',
)
);
echo Html::_('checkbox')->render(
array( // List of options
'val-1' => 'Label 1',
'val-2' => 'Custom Label',
'val-3' => 'Var 3',
),
'test', // Name
array('val-1', 'val-3'), // Checked values
array('data-rel' => 'tooltip') // Attrs
);
echo Html::_('checkbox')->render(
array( // List of options
'val-1' => 'Label 1',
'val-2' => 'Custom Label',
'val-3' => 'Var 3',
),
'test', // Name
array('val-1', 'val-3'), // Checked values
array('data-rel' => 'tooltip') // Attrs
);
echo Html::_('checkbox')->render(
array( // List of options
'val-1' => 'Label 1',
'val-2' => 'Custom Label',
'val-3' => 'Var 3',
),
'test', // Name
'val-1', // Checked value
array(), // Attrs
function ($list, $name, $value, $id, $text, $attrs) { // Custom render function
$alias = $value;
$inpClass = 'jb-val-' . $alias;
$input = $list->input($name, $value, $id, $inpClass, $attrs);
$text = '<span class="label-title">' . $text . '</span>';
$label = $list->label($id, $alias, $text);
return implode(PHP_EOL, array($input, $label));
}
);
echo Html::_('radio')->render(
array( // List value
'val-1' => 'Label 1',
'val-2' => 'Custom Label',
'val-3' => 'Var 3',
),
'test', // Checked value
array('val-1', 'val-3'),
array('data-rel' => 'tooltip')
);
echo Html::_('radio')->render(
array( // List of options
'val-1' => 'Label 1',
'val-2' => 'Custom Label',
'val-3' => 'Var 3',
),
'test', // Name
'val-1', // Checked value
array(), // Attrs
true // Wrap input by label
);
echo Html::_('radio')->render(
array(
'val-1' => 'Label 1',
'val-2' => 'Custom Label',
'val-3' => 'Var 3',
),
'test',
'val-1',
array(),
function ($list, $name, $value, $id, $text, $attrs) {
$alias = $value;
$inpClass = 'jb-val-' . $alias;
$input = $list->input($name, $value, $id, $inpClass, $attrs);
$text = '<span class="label-title">' . $text . '</span>';
$label = $list->label($id, $alias, $text);
return implode(PHP_EOL, array($input, $label));
}
);
echo Html::_('radio')->render(
array( // List of options
'val-1' => 'Label 1',
'val-2' => 'Custom Label',
'val-3' => 'Var 3',
),
'test', // Name
'val-8', // Undefined value
array(), // Atrs
true // Wrap inputs by labels
);
echo Html::_('datalist')->render(
array( // Keys and Values
'Label' => 'Content text',
'Custom label' => 'List text',
),
array( // Attrs
'class' => 'test',
'id' => 'custom',
)
);
echo Html::_('select')->render(
array(
'val-1' => 'Label 1',
'test' => 'Label test',
'custom' => 'Custom',
),
'test',
'custom',
array(
'data-title' => 'My form select',
)
);
echo Html::_('select')->render(
array(
'val-1' => 'Label 1',
'test' => 'Label test',
'custom' => 'Custom',
'simple' => 'Simple label',
'moscow' => 'Moscow',
),
'test',
array('test', 'moscow'),
array(
'multiple' => true,
)
);
/**
* If selected params is array. For check selected option taken last array var.
* If option is not exists created new option. See output.
*/
echo Html::_('select')->render(
array(
'val-1' => 'Label 1',
'test' => 'Label test',
'custom' => 'Custom',
'simple' => 'Simple label',
'moscow' => 'Moscow',
),
'test',
array('test', 'moscow', 'no-value')
);
echo Html::_('select')->render(
array(
'val-1' => 'Label 1',
'test' => 'Test label',
array(
'gr-test' => 'Group test 1',
'val-1' => 'No exits in group',
)
),
'test',
array('test', 'moscow', 'no-value')
);
echo Html::_('hidden')->render('image', 'my-value', 'my-class', 'unique', array('data-profile' => 'user-1'));
echo Html::_('hidden')->group(array(
'my-name' => 'My name value',
'user' => 'Administrator',
'array' => array(
'value' => 'my value',
'class' => 'array-hidden',
'id' => 'hide-id',
),
));
echo Html::_('iframe')->render('http://my-site.com/page', 'my-class', 'my-id', array('data-rel' => 'my-iframe'));
echo Html::_('textarea')->render(
'test',
'Text area content',
'my-class',
'my-id',
array(
'data-rel' => 'tooltip',
'data-title' => 'Enter description',
)
);
echo Html::_('tag')->render('My content', 'custom-class', 'unique', array(
'tag' => 'div',
'title' => 'Custom title'
));
echo Html::_('input')->render(
'test',
'My value',
'',
'',
array('data' => array(
'test' => 'val',
'json' => array(
'param-1' => 'val-1',
'param-2' => 'val-2',
)
))
);