smarty-php / smarty-php/smarty
Extend function "html_options"
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- PHP
- Stars
- 2.3k
- Forks
- 709
- PR merge metrics
- No merged PRs in 30d
Description
- Add parameter
datalist(type: bool, default: false) to generate<datalist>if set true - Add parameters
placeholder_valueandplaceholder_output(type: string, default: null) to prepend<option value="$param['placeholder_value']" disabled>$param['placeholder_output']</option> - Add parameter
option_class(type: string, default: null) to set option class or pass '' to omit option class (in current versionclassattribute adds tooptiontags too - this break styles sometimes).
and start using SimpleXMLElement or DOMElement to generate tags - no need escape attribute values and detect boolean attributes:
$doc = (new DOMImplementation())->createDocument(null, 'html');
$tag = empty($param['datalist']) ? 'select' : 'datalist';
$parent = $html->appendChild($doc->createElement($tag));
foreach ($attributes as $key => $value) {
$parent->setAttribute($key, $value);
}
foreach ($options as $key => $value) {
$option = $parent->appendChild($doc->createElement('option', $value));
$option->setAttribute('value', $key);
if (in_array($key, (array) $selected, true)) {
$option->setAttribute('selected', '');
}
}
return $doc->saveHTML($parent);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the existing html_options implementation and trace how it currently builds the select, attributes, and option tags. Review the requested datalist, placeholder, and option_class parameters alongside the proposed DOMElement approach. Done means the helper supports those parameters and generates correctly escaped select or datalist markup with the requested option attributes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100