Final Class Yiisoft\Html\Html
| Inheritance | Yiisoft\ |
|---|
Html provides a set of static methods for generating commonly used HTML tags.
Nearly all the methods in this class allow setting additional HTML attributes for the HTML tags they generate.
You can specify, for example, class, style or id for an HTML element using the $attributes parameter. See the
documentation of the {@see \
Public Methods
| Method | Description | Defined By |
|---|---|---|
| a() | Generates a hyperlink tag. | Yiisoft\ |
| abbr() | Generates a {@see Abbr} tag. | Yiisoft\ |
| addCssClass() | Adds a CSS class (or several classes) to the specified attributes. | Yiisoft\ |
| addCssStyle() | Adds the specified CSS styles to the HTML attributes. | Yiisoft\ |
| address() | Generates a {@see Address} tag. | Yiisoft\ |
| area() | Generates a {@see Area} tag. | Yiisoft\ |
| article() | Generates a {@see Article} tag. | Yiisoft\ |
| aside() | Generates a {@see Aside} tag. | Yiisoft\ |
| audio() | Generates a {@see Audio} tag. | Yiisoft\ |
| b() | Generates a {@see B} tag. | Yiisoft\ |
| base() | Generates a {@see Base} tag. | Yiisoft\ |
| bdi() | Generates a {@see Bdi} tag. | Yiisoft\ |
| bdo() | Generates a {@see Bdo} tag. | Yiisoft\ |
| blockquote() | Generates a {@see Blockquote} tag. | Yiisoft\ |
| body() | Generates a {@see Body} tag. | Yiisoft\ |
| br() | Generates a {@see Br} tag. | Yiisoft\ |
| button() | Generates a button tag. | Yiisoft\ |
| buttonInput() | Generates an {@see Input} button. | Yiisoft\ |
| canvas() | Generates a {@see Canvas} tag. | Yiisoft\ |
| caption() | Generates a {@see Caption} tag. | Yiisoft\ |
| checkbox() | Generates a checkbox {@see Input}. | Yiisoft\ |
| checkboxList() | Generates a list of checkboxes. | Yiisoft\ |
| cite() | Generates a {@see Cite} tag. | Yiisoft\ |
| closeTag() | Generates an end tag. | Yiisoft\ |
| code() | Generates a {@see Code} tag. | Yiisoft\ |
| col() | Generates a {@see Col} tag. | Yiisoft\ |
| colgroup() | Generates a {@see Colgroup} tag. | Yiisoft\ |
| color() | Generates a color {@see Input} field. | Yiisoft\ |
| cssFile() | Generates a {@see Link} tag that refers to an CSS file. | Yiisoft\ |
| cssStyleFromArray() | Converts a CSS style array into a string representation. | Yiisoft\ |
| cssStyleToArray() | Converts a CSS style string into an array representation. | Yiisoft\ |
| data() | Generates a {@see Data} tag. | Yiisoft\ |
| datalist() | Generates a {@see Datalist} tag. | Yiisoft\ |
| dd() | Generates a {@see Dd} tag. | Yiisoft\ |
| del() | Generates a {@see Del} tag. | Yiisoft\ |
| details() | Generates a {@see Details} tag. | Yiisoft\ |
| dfn() | Generates a {@see Dfn} tag. | Yiisoft\ |
| dialog() | Generates a {@see Dialog} tag. | Yiisoft\ |
| div() | Generates a {@see Div} tag. | Yiisoft\ |
| dl() | Generates a {@see Dl} tag. | Yiisoft\ |
| dt() | Generates a {@see Dt} tag. | Yiisoft\ |
| em() | Generates a {@see Em} tag. | Yiisoft\ |
| embed() | Generates a {@see Embed} tag. | Yiisoft\ |
| encode() | Encodes special characters into HTML entities for use as a tag content
i.e. <div>tag content</div>. |
Yiisoft\ |
| encodeAttribute() | Encodes special characters into HTML entities for use as HTML tag quoted attribute value
i.e. <input value="my-value">. |
Yiisoft\ |
| encodeUnquotedAttribute() | Encodes special characters into HTML entities for use as HTML tag unquoted attribute value
i.e. <input value=my-value>. |
Yiisoft\ |
| escapeJavaScriptStringValue() | Escape special characters for use as JavaScript string value in a <script> tag: |
Yiisoft\ |
| fieldset() | Generates a {@see Fieldset} tag. | Yiisoft\ |
| figcaption() | Generates a {@see Figcaption} tag. | Yiisoft\ |
| figure() | Generates a {@see Figure} tag. | Yiisoft\ |
| file() | Generates a file input field. | Yiisoft\ |
| footer() | Generates a {@see Footer} tag. | Yiisoft\ |
| form() | Generates a {@see Form} tag. | Yiisoft\ |
| generateId() | Generates a unique sequential ID composed of the given prefix, an hrtime(true) timestamp,
and a counter that increments with each call sharing the same timestamp. |
Yiisoft\ |
| getArrayableName() | Yiisoft\ |
|
| getNonArrayableName() | Yiisoft\ |
|
| h1() | Generates a {@see H1} tag. | Yiisoft\ |
| h2() | Generates a {@see H2} tag. | Yiisoft\ |
| h3() | Generates a {@see H3} tag. | Yiisoft\ |
| h4() | Generates a {@see H4} tag. | Yiisoft\ |
| h5() | Generates a {@see H5} tag. | Yiisoft\ |
| h6() | Generates a {@see H6} tag. | Yiisoft\ |
| head() | Generates a {@see Head} tag. | Yiisoft\ |
| header() | Generates a {@see Header} tag. | Yiisoft\ |
| hgroup() | Generates a {@see Hgroup} tag. | Yiisoft\ |
| hr() | Generates a {@see Hr} tag. | Yiisoft\ |
| html() | Generates a {@see Html} tag. | Yiisoft\ |
| i() | Generates a {@see I} tag. | Yiisoft\ |
| iframe() | Generates a {@see Iframe} tag. | Yiisoft\ |
| img() | Generates an {@see Img} tag. | Yiisoft\ |
| input() | Generates an {@see Input} type of the given type. | Yiisoft\ |
| ins() | Generates a {@see Ins} tag. | Yiisoft\ |
| javaScriptFile() | Generates a {@see Script} tag that refers to a JavaScript file. | Yiisoft\ |
| kbd() | Generates a {@see Kbd} tag. | Yiisoft\ |
| label() | Generates a {@see Label} tag. | Yiisoft\ |
| legend() | Generates a {@see Legend} tag. | Yiisoft\ |
| li() | Generates a {@see Li} tag. | Yiisoft\ |
| link() | Generates a {@see Link} tag. | Yiisoft\ |
| mailto() | Generates a mailto hyperlink tag. | Yiisoft\ |
| main() | Generates a {@see Main} tag. | Yiisoft\ |
| map() | Generates a {@see Map} tag. | Yiisoft\ |
| mark() | Generates a {@see Mark} tag. | Yiisoft\ |
| menu() | Generates a {@see Menu} tag. | Yiisoft\ |
| meta() | Generates a {@see Meta} tag. | Yiisoft\ |
| meter() | Generates a {@see Meter} tag. | Yiisoft\ |
| nav() | Generates a {@see Nav} tag. | Yiisoft\ |
| normalTag() | Generates a normal HTML tag. | Yiisoft\ |
| normalizeRegexpPattern() | Normalize PCRE regular expression to use in the "pattern" HTML attribute:
- convert \ |
Yiisoft\ |
| noscript() | Generates a {@see Noscript} tag. | Yiisoft\ |
| object() | Generates a {@see ObjectTag} tag. | Yiisoft\ |
| ol() | Generates a {@see Ol} tag. | Yiisoft\ |
| openTag() | Generates a start tag. | Yiisoft\ |
| optgroup() | Generates a {@see Optgroup} tag. | Yiisoft\ |
| option() | Generates a {@see Option} tag. | Yiisoft\ |
| output() | Generates a {@see Output} tag. | Yiisoft\ |
| p() | Generates a {@see P} tag. | Yiisoft\ |
| passwordInput() | Generates a password input field. | Yiisoft\ |
| picture() | Generates a {@see Picture} tag. | Yiisoft\ |
| pre() | Generates a {@see Pre} tag. | Yiisoft\ |
| progress() | Generates a {@see Progress} tag. | Yiisoft\ |
| q() | Generates a {@see Q} tag. | Yiisoft\ |
| radio() | Generates a radio button {@see Input}. | Yiisoft\ |
| radioList() | Generates a list of radio buttons. | Yiisoft\ |
| range() | Generates a range {@see Range}. | Yiisoft\ |
| removeCssClass() | Removes a CSS class from the specified attributes. | Yiisoft\ |
| removeCssStyle() | Removes the specified CSS styles from the HTML attributes. | Yiisoft\ |
| renderTagAttributes() | Renders the HTML tag attributes. | Yiisoft\ |
| resetButton() | Generates a reset button tag. | Yiisoft\ |
| resetInput() | Generates a reset {@see Input} button. | Yiisoft\ |
| rp() | Generates a {@see Rp} tag. | Yiisoft\ |
| rt() | Generates a {@see Rt} tag. | Yiisoft\ |
| ruby() | Generates a {@see Ruby} tag. | Yiisoft\ |
| s() | Generates a {@see S} tag. | Yiisoft\ |
| samp() | Generates a {@see Samp} tag. | Yiisoft\ |
| script() | Generates a {@see Script} tag. | Yiisoft\ |
| search() | Generates a {@see Search} tag. | Yiisoft\ |
| section() | Generates a {@see Section} tag. | Yiisoft\ |
| select() | Generates a {@see Select} tag. | Yiisoft\ |
| slot() | Generates a {@see Slot} tag. | Yiisoft\ |
| small() | Generates a {@see Small} tag. | Yiisoft\ |
| source() | Generates a {@see Source} tag. | Yiisoft\ |
| span() | Generates a {@see Span} tag. | Yiisoft\ |
| strong() | Generates a {@see Strong} tag. | Yiisoft\ |
| style() | Generates a {@see Style} tag. | Yiisoft\ |
| sub() | Generates a {@see Sub} tag. | Yiisoft\ |
| submitButton() | Generates a submit button tag. | Yiisoft\ |
| submitInput() | Generates submit {@see Input} button. | Yiisoft\ |
| summary() | Generates a {@see Summary} tag. | Yiisoft\ |
| sup() | Generates a {@see Sup} tag. | Yiisoft\ |
| table() | Generates a {@see Table} tag. | Yiisoft\ |
| tag() | Generates a complete HTML tag. | Yiisoft\ |
| tbody() | Generates a {@see Tbody} tag. | Yiisoft\ |
| td() | Generates a {@see Td} tag. | Yiisoft\ |
| template() | Generates a {@see Template} tag. | Yiisoft\ |
| textInput() | Generates a text {@see Input} field. | Yiisoft\ |
| textarea() | Generates a {@see Textarea} input. | Yiisoft\ |
| tfoot() | Generates a {@see Tfoot} tag. | Yiisoft\ |
| th() | Generates a {@see Th} tag. | Yiisoft\ |
| thead() | Generates a {@see Thead} tag. | Yiisoft\ |
| time() | Generates a {@see Time} tag. | Yiisoft\ |
| title() | Generates a {@see Title} tag. | Yiisoft\ |
| tr() | Generates a {@see Tr} tag. | Yiisoft\ |
| track() | Generates a {@see Track} tag. | Yiisoft\ |
| u() | Generates a {@see U} tag. | Yiisoft\ |
| ul() | Generates a {@see Ul} tag. | Yiisoft\ |
| var() | Generates a {@see VarTag} tag. | Yiisoft\ |
| video() | Generates a {@see Video} tag. | Yiisoft\ |
| voidTag() | Generates a void HTML tag. | Yiisoft\ |
| wbr() | Generates a {@see Wbr} tag. | Yiisoft\ |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| ATTRIBUTES_WITH_CONCATENATED_VALUES | [ 'class', 'aria-describedby', ] |
List of tag attributes which values should be concatenated with space.
In particular, if the value of the attribute with the name attribute is ['value1', 'value2'], the result will
be attribute="value1 value2". |
Yiisoft\ |
| DATA_ATTRIBUTES | [ 'data', 'data-ng', 'ng', 'aria', ] |
List of tag attributes that should be specially handled when their values are of array type.
In particular, if the value of the data attribute is ['name' => 'xyz', 'age' => 13], two attributes will be
generated instead of one: data-name="xyz" data-age="13". |
Yiisoft\ |
Method Details
Generates a hyperlink tag.
See also Yiisoft\
| public static Yiisoft\ | ||
| $content | string|\ |
The tag content. |
| $url | ?string | |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function a(string|Stringable|int|float|null $content = '', ?string $url = null, array $attributes = []): A
{
$tag = new A();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
if ($content !== '') {
$tag = $tag->content($content);
}
if ($url !== null) {
$tag = $tag->url($url);
}
return $tag;
}
Generates a {@see Abbr} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function abbr(string|Stringable|int|float|null $content = '', array $attributes = []): Abbr
{
$tag = new Abbr();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Adds a CSS class (or several classes) to the specified attributes.
If the CSS class is already in the attributes, it will not be added again. If class specification at given attributes is an array, and some class placed there with the named (string) key, overriding of such key will have no effect. For example:
$attributes = ['class' => ['persistent' => 'initial']];
// ['class' => ['persistent' => 'initial']];
Html::addCssClass($attributes, ['persistent' => 'override']);
See also removeCssClass().
| public static void addCssClass ( array &$attributes, (\ | ||
| $attributes | array |
The attributes to be modified. All string values in the array must be valid UTF-8 strings. |
| $class | (\ |
The CSS class(es) to be added. Null values will be ignored. When passing an array, use a boolean value to conditionally include/exclude a class by its key. |
public static function addCssClass(array &$attributes, BackedEnum|array|string|null $class): void
{
if ($class === null) {
return;
}
if ($class instanceof BackedEnum) {
if (is_int($class->value)) {
return;
}
$class = $class->value;
}
if (is_array($class)) {
$filteredClass = [];
foreach ($class as $key => $value) {
if (is_bool($value)) {
if ($value && is_string($key)) {
$filteredClass[] = $key;
}
continue;
}
if ($value instanceof BackedEnum) {
$value = is_string($value->value) ? $value->value : null;
}
if ($value !== null) {
if (is_int($key) && array_key_exists($key, $filteredClass)) {
$filteredClass[] = $value;
} else {
$filteredClass[$key] = $value;
}
}
}
if (empty($filteredClass)) {
return;
}
$class = $filteredClass;
}
if (isset($attributes['class'])) {
if (is_array($attributes['class'])) {
/** @psalm-var string[] $attributes['class'] */
$attributes['class'] = self::mergeCssClasses($attributes['class'], (array) $class);
} else {
/**
* @psalm-var string $attributes['class']
* @var string[] $classes We assume that `$attributes['class']` is valid UTF-8 string, so `preg_split()`
* never returns `false`.
*/
$classes = preg_split('/\s+/' , $attributes['class'], -1, PREG_SPLIT_NO_EMPTY);
$classes = self::mergeCssClasses($classes, (array) $class);
$attributes['class'] = is_array($class) ? $classes : implode(' ', $classes);
}
} else {
$attributes['class'] = $class;
}
}
Adds the specified CSS styles to the HTML attributes.
If the attributes already contain a style element, the new style will be merged
with the existing one. If a CSS property exists in both the new and the old styles,
the old one may be overwritten if $overwrite is true.
For example,
Html::addCssStyle($attributes, 'width: 100px; height: 200px');
See also removeCssStyle().
| public static void addCssStyle ( array &$attributes, string|string[] $style, boolean $overwrite = true ) | ||
| $attributes | array |
The HTML attributes to be modified. |
| $style | string|string[] |
The new style string (e.g. |
| $overwrite | boolean |
Whether to overwrite existing CSS properties if the new style contains them too. |
public static function addCssStyle(array &$attributes, array|string $style, bool $overwrite = true): void
{
if (!empty($attributes['style'])) {
/** @psalm-var array<string,string>|string $attributes['style'] */
$oldStyle = is_array($attributes['style']) ? $attributes['style'] : self::cssStyleToArray($attributes['style']);
$newStyle = is_array($style) ? $style : self::cssStyleToArray($style);
if (!$overwrite) {
foreach ($newStyle as $property => $_value) {
if (isset($oldStyle[$property])) {
unset($newStyle[$property]);
}
}
}
$style = array_merge($oldStyle, $newStyle);
}
$attributes['style'] = is_array($style) ? self::cssStyleFromArray($style) : $style;
}
Generates a {@see Address} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function address(string|Stringable|int|float|null $content = '', array $attributes = []): Address
{
$tag = new Address();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Area} tag.
| public static Yiisoft\ | ||
| $alt | string|null |
The alternate text for the area. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function area(?string $alt = null, array $attributes = []): Area
{
$tag = new Area();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
if ($alt !== null) {
$tag = $tag->alt($alt);
}
return $tag;
}
Generates a {@see Article} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function article(string|Stringable|int|float|null $content = '', array $attributes = []): Article
{
$tag = new Article();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Aside} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function aside(string|Stringable|int|float|null $content = '', array $attributes = []): Aside
{
$tag = new Aside();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Audio} tag.
| public static Yiisoft\ |
public static function audio(): Audio
{
return new Audio();
}
Generates a {@see B} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function b(string|Stringable|int|float|null $content = '', array $attributes = []): B
{
$tag = new B();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Base} tag.
| public static Yiisoft\ | ||
| $url | string|null |
The base URL for the document. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function base(?string $url = null, array $attributes = []): Base
{
$tag = new Base();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
if ($url !== null) {
$tag = $tag->href($url);
}
return $tag;
}
Generates a {@see Bdi} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function bdi(string|Stringable|int|float|null $content = '', array $attributes = []): Bdi
{
$tag = new Bdi();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Bdo} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function bdo(string|Stringable|int|float|null $content = '', array $attributes = []): Bdo
{
$tag = new Bdo();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Blockquote} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function blockquote(string|Stringable|int|float|null $content = '', array $attributes = []): Blockquote
{
$tag = new Blockquote();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Body} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function body(string|Stringable|int|float|null $content = '', array $attributes = []): Body
{
$tag = new Body();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Br} tag.
| public static Yiisoft\ |
public static function br(): Br
{
return new Br();
}
Generates a {@see Canvas} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function canvas(string|Stringable|int|float|null $content = '', array $attributes = []): Canvas
{
$tag = new Canvas();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Caption} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function caption(string|Stringable|int|float|null $content = '', array $attributes = []): Caption
{
$tag = new Caption();
if ($content !== '') {
$tag = $tag->content($content);
}
if ($attributes !== []) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a checkbox {@see Input}.
See also Yiisoft\
| public static Yiisoft\ | ||
| $name | string|null |
The name attribute. |
| $value | boolean|float|integer|string|\ |
The value attribute. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function checkbox(
?string $name = null,
bool|float|int|string|Stringable|null $value = null,
array $attributes = [],
): Checkbox {
$tag = Input::checkbox($name, $value);
return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}
Generates a list of checkboxes.
| public static Yiisoft\ | ||
| $name | string | |
public static function checkboxList(string $name): CheckboxList
{
return new CheckboxList($name);
}
Generates a {@see Cite} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function cite(string|Stringable|int|float|null $content = '', array $attributes = []): Cite
{
$tag = new Cite();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates an end tag.
See also \
| public static string closeTag ( string $name ) | ||
| $name | string |
The tag name. |
public static function closeTag(string $name): string
{
return "</$name>";
}
Generates a {@see Code} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. If content includes HTML tags or special characters like |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function code(string|Stringable|int|float|null $content = '', array $attributes = []): Code
{
$tag = new Code();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Col} tag.
| public static Yiisoft\ | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function col(array $attributes = []): Col
{
$tag = new Col();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a {@see Colgroup} tag.
| public static Yiisoft\ | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function colgroup(array $attributes = []): Colgroup
{
$tag = new Colgroup();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a color {@see Input} field.
See also Yiisoft\
| public static Yiisoft\ | ||
| $name | string|null |
The name attribute. |
| $value | string|\ |
The value attribute. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function color(
?string $name = null,
string|Stringable|null $value = null,
array $attributes = [],
): Color {
$tag = Input::color($name, $value);
return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}
Generates a {@see Link} tag that refers to an CSS file.
| public static Yiisoft\ | ||
| $url | string |
The URL of the CSS file. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function cssFile(string $url, array $attributes = []): Link
{
$tag = Link::toCssFile($url);
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
return $tag;
}
Converts a CSS style array into a string representation.
For example,
// width: 100px; height: 200px;
Html::cssStyleFromArray(['width' => '100px', 'height' => '200px']);
See also cssStyleToArray().
| public static string|null cssStyleFromArray ( array | ||
| $style | array |
The CSS style array. The array keys are the CSS property names, and the array values are the corresponding CSS property values. |
| return | string|null |
The CSS style string. If the CSS style is empty, a null will be returned. |
|---|---|---|
public static function cssStyleFromArray(array $style): ?string
{
$result = '';
foreach ($style as $name => $value) {
$result .= "$name: $value; ";
}
// Return null if empty to avoid rendering the "style" attribute.
return $result === '' ? null : rtrim($result);
}
Converts a CSS style string into an array representation.
The array keys are the CSS property names, and the array values are the corresponding CSS property values.
For example,
// ['width' => '100px', 'height' => '200px']
Html::cssStyleToArray('width: 100px; height: 200px;');
See also cssStyleFromArray().
| public static array cssStyleToArray ( string|\ | ||
| $style | string|\ |
The CSS style string. |
| return | array |
The array representation of the CSS style. |
|---|---|---|
public static function cssStyleToArray(string|Stringable $style): array
{
$result = [];
foreach (explode(';', (string) $style) as $property) {
$property = explode(':', $property);
if (count($property) > 1) {
$result[trim($property[0])] = trim($property[1]);
}
}
return $result;
}
Generates a {@see Data} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function data(string|Stringable|int|float|null $content = '', array $attributes = []): Data
{
$tag = new Data();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Datalist} tag.
| public static Yiisoft\ | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function datalist(array $attributes = []): Datalist
{
$tag = new Datalist();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a {@see Dd} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function dd(string|Stringable|int|float|null $content = '', array $attributes = []): Dd
{
$tag = new Dd();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Del} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function del(string|Stringable|int|float|null $content = '', array $attributes = []): Del
{
$tag = new Del();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Details} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function details(string|Stringable|int|float|null $content = '', array $attributes = []): Details
{
$tag = new Details();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Dfn} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function dfn(string|Stringable|int|float|null $content = '', array $attributes = []): Dfn
{
$tag = new Dfn();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Dialog} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function dialog(string|Stringable|int|float|null $content = '', array $attributes = []): Dialog
{
$tag = new Dialog();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Div} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function div(string|Stringable|int|float|null $content = '', array $attributes = []): Div
{
$tag = new Div();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Dl} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function dl(string|Stringable|int|float|null $content = '', array $attributes = []): Dl
{
$tag = new Dl();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Dt} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function dt(string|Stringable|int|float|null $content = '', array $attributes = []): Dt
{
$tag = new Dt();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Em} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function em(string|Stringable|int|float|null $content = '', array $attributes = []): Em
{
$tag = new Em();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Embed} tag.
| public static Yiisoft\ | ||
| $src | string|null |
The URL of the embedded resource. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function embed(?string $src = null, array $attributes = []): Embed
{
$tag = new Embed();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
if ($src !== null) {
$tag = $tag->src($src);
}
return $tag;
}
Encodes special characters into HTML entities for use as a tag content
i.e. <div>tag content</div>.
Characters encoded are: &, <, >.
| public static string encode ( mixed $content, boolean $doubleEncode = true, string $encoding = 'UTF-8' ) | ||
| $content | mixed |
The content to be encoded. |
| $doubleEncode | boolean |
If already encoded entities should be encoded. |
| $encoding | string |
The encoding to use, defaults to "UTF-8". |
| return | string |
Encoded content. |
|---|---|---|
public static function encode(mixed $content, bool $doubleEncode = true, string $encoding = 'UTF-8'): string
{
return htmlspecialchars(
(string) $content,
ENT_NOQUOTES | ENT_SUBSTITUTE | ENT_HTML5,
$encoding,
$doubleEncode,
);
}
Encodes special characters into HTML entities for use as HTML tag quoted attribute value
i.e. <input value="my-value">.
Characters encoded are: &, <, >, ", ', U+0000 (null).
| public static string encodeAttribute ( mixed $value, boolean $doubleEncode = true, string $encoding = 'UTF-8' ) | ||
| $value | mixed |
The attribute value to be encoded. |
| $doubleEncode | boolean |
If already encoded entities should be encoded. |
| $encoding | string |
The encoding to use, defaults to "UTF-8". |
| return | string |
Encoded attribute value. |
|---|---|---|
public static function encodeAttribute(mixed $value, bool $doubleEncode = true, string $encoding = 'UTF-8'): string
{
$value = htmlspecialchars(
(string) $value,
ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5,
$encoding,
$doubleEncode,
);
return strtr($value, [
"\u{0000}" => '�', // U+0000 NULL
]);
}
Encodes special characters into HTML entities for use as HTML tag unquoted attribute value
i.e. <input value=my-value>.
Characters encoded are: &, <, >, ", ', `, =, tab, space, U+000A (form feed), U+0000 (null).
| public static string encodeUnquotedAttribute ( mixed $value, boolean $doubleEncode = true, string $encoding = 'UTF-8' ) | ||
| $value | mixed |
The attribute value to be encoded. |
| $doubleEncode | boolean |
If already encoded entities should be encoded. |
| $encoding | string |
The encoding to use, defaults to "UTF-8". |
| return | string |
Encoded attribute value. |
|---|---|---|
public static function encodeUnquotedAttribute(
mixed $value,
bool $doubleEncode = true,
string $encoding = 'UTF-8',
): string {
$value = htmlspecialchars(
(string) $value,
ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5,
$encoding,
$doubleEncode,
);
return strtr($value, [
"\t" => '	', // U+0009 CHARACTER TABULATION (tab)
"\n" => '
', // U+000A LINE FEED (LF)
"\u{000c}" => '', // U+000C FORM FEED (FF)
"\u{0000}" => '�', // U+0000 NULL
' ' => ' ', // U+0020 SPACE
'=' => '=', // U+003D EQUALS SIGN (=)
'`' => '`', // U+0060 GRAVE ACCENT (`)
]);
}
Escape special characters for use as JavaScript string value in a <script> tag:
<script></script>
| public static string escapeJavaScriptStringValue ( mixed $value ) | ||
| $value | mixed |
JavaScript string. |
| return | string |
Escaped JavaScript string. |
|---|---|---|
public static function escapeJavaScriptStringValue(mixed $value): string
{
return strtr((string) $value, [
'/' => '\/',
'"' => '\"',
"'" => "\'",
'\\' => '\\\\',
]);
}
Generates a {@see Fieldset} tag.
| public static Yiisoft\ | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function fieldset(array $attributes = []): Fieldset
{
$tag = new Fieldset();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a {@see Figcaption} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function figcaption(string|Stringable|int|float|null $content = '', array $attributes = []): Figcaption
{
$tag = new Figcaption();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Figure} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function figure(string|Stringable|int|float|null $content = '', array $attributes = []): Figure
{
$tag = new Figure();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a file input field.
To use a file input field, you should set the enclosing form's "enctype" attribute to be "multipart/form-data". After the form is submitted, the uploaded file information can be obtained via $_FILES[$name] (see PHP documentation).
See also Yiisoft\
| public static Yiisoft\ | ||
| $name | string|null |
The name attribute. |
| $value | boolean|float|integer|string|\ |
The value attribute. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function file(
?string $name = null,
bool|float|int|string|Stringable|null $value = null,
array $attributes = [],
): File {
$tag = Input::file($name, $value);
return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}
Generates a {@see Form} tag.
| public static Yiisoft\ | ||
| $action | string|null |
The URL to use for form submission. |
| $method | string|null |
The method attribute value. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function form(?string $action = null, ?string $method = null, array $attributes = []): Form
{
$tag = new Form();
if ($action !== null) {
$attributes['action'] = $action;
}
if ($method !== null) {
$attributes['method'] = $method;
}
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a unique sequential ID composed of the given prefix, an hrtime(true) timestamp,
and a counter that increments with each call sharing the same timestamp.
See also https://github.com/yiisoft/html/blob/master/docs/testing-id-generation.md for controlling ID generation in tests.
| public static string generateId ( string $prefix = 'i' ) | ||
| $prefix | string |
Prefix to prepend to the generated ID. |
| return | string |
Autogenerated ID. |
|---|---|---|
public static function generateId(string $prefix = 'i'): string
{
return IdGenerator::generate($prefix);
}
| public static string getArrayableName ( string $name ) | ||
| $name | string | |
public static function getArrayableName(string $name): string
{
return !str_ends_with($name, '[]') ? $name . '[]' : $name;
}
| public static string getNonArrayableName ( string $name ) | ||
| $name | string | |
public static function getNonArrayableName(string $name): string
{
return str_ends_with($name, '[]') ? substr($name, 0, -2) : $name;
}
Generates a {@see H1} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function h1(string|Stringable|int|float|null $content = '', array $attributes = []): H1
{
$tag = new H1();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see H2} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function h2(string|Stringable|int|float|null $content = '', array $attributes = []): H2
{
$tag = new H2();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see H3} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function h3(string|Stringable|int|float|null $content = '', array $attributes = []): H3
{
$tag = new H3();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see H4} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function h4(string|Stringable|int|float|null $content = '', array $attributes = []): H4
{
$tag = new H4();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see H5} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function h5(string|Stringable|int|float|null $content = '', array $attributes = []): H5
{
$tag = new H5();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see H6} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function h6(string|Stringable|int|float|null $content = '', array $attributes = []): H6
{
$tag = new H6();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Head} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function head(string|Stringable|int|float|null $content = '', array $attributes = []): Head
{
$tag = new Head();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Header} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function header(string|Stringable|int|float|null $content = '', array $attributes = []): Header
{
$tag = new Header();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Hgroup} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function hgroup(string|Stringable|int|float|null $content = '', array $attributes = []): Hgroup
{
$tag = new Hgroup();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Hr} tag.
| public static Yiisoft\ | ||
| $attributes | array | |
public static function hr(array $attributes = []): Hr
{
$tag = new Hr();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a {@see Html} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $lang | string|null |
The document language. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function html(string|Stringable|int|float|null $content = '', ?string $lang = null, array $attributes = []): Tag\Html
{
$tag = new Tag\Html();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
if ($content !== '') {
$tag = $tag->content($content);
}
if ($lang !== null) {
$tag = $tag->lang($lang);
}
return $tag;
}
Generates a {@see I} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function i(string|Stringable|int|float|null $content = '', array $attributes = []): I
{
$tag = new I();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Iframe} tag.
| public static Yiisoft\ | ||
| $src | string|null |
The src attribute value. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function iframe(?string $src = null, array $attributes = []): Iframe
{
$tag = new Iframe();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
if ($src !== null) {
$tag = $tag->src($src);
}
return $tag;
}
Generates an {@see Img} tag.
| public static Yiisoft\ | ||
| $url | string|null |
The image URL. |
| $alt | string|null |
Alt text. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function img(?string $url = null, ?string $alt = '', array $attributes = []): Img
{
$tag = new Img();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
if ($url !== null) {
$tag = $tag->src($url);
}
if ($alt !== null) {
$tag = $tag->alt($alt);
}
return $tag;
}
Generates an {@see Input} type of the given type.
| public static Yiisoft\ | ||
| $type | string |
The type attribute. |
| $name | string|null |
The name attribute. If it is |
| $value | boolean|float|integer|string|\ |
The value attribute. If it is |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function input(
string $type,
?string $name = null,
bool|float|int|string|Stringable|null $value = null,
array $attributes = [],
): Input {
$tag = (new Input())->type($type);
if ($name !== null) {
$tag = $tag->name($name);
}
if ($value !== null) {
$tag = $tag->value($value);
}
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
return $tag;
}
Generates a {@see Ins} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function ins(string|Stringable|int|float|null $content = '', array $attributes = []): Ins
{
$tag = new Ins();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Script} tag that refers to a JavaScript file.
| public static Yiisoft\ | ||
| $url | string |
The URL of the JavaScript file. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function javaScriptFile(string $url, array $attributes = []): Script
{
$tag = (new Script())->url($url);
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
return $tag;
}
Generates a {@see Kbd} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function kbd(string|Stringable|int|float|null $content = '', array $attributes = []): Kbd
{
$tag = new Kbd();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Label} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Label text. |
| $for | string|null |
The ID of the HTML element that this label is associated with. If this is null, the "for" attribute will not be generated. |
public static function label(string|Stringable|int|float|null $content = '', ?string $for = null): Label
{
$tag = new Label();
if ($for !== null) {
$tag = $tag->forId($for);
}
if ($content !== '') {
$tag = $tag->content($content);
}
return $tag;
}
Generates a {@see Legend} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
The tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function legend(string|Stringable|int|float|null $content = '', array $attributes = []): Legend
{
$tag = new Legend();
if ($content !== '') {
$tag = $tag->content($content);
}
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a {@see Li} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function li(string|Stringable|int|float|null $content = '', array $attributes = []): Li
{
$tag = new Li();
if ($attributes !== []) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Link} tag.
| public static Yiisoft\ | ||
| $url | string|null |
The destination of the link. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function link(?string $url = null, array $attributes = []): Link
{
$tag = new Link();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
if ($url !== null) {
$tag = $tag->url($url);
}
return $tag;
}
Generates a mailto hyperlink tag.
See also Yiisoft\
| public static Yiisoft\ | ||
| $content | string|\ |
|
| ?string | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function mailto(string|Stringable|int|float|null $content, ?string $mail = null, array $attributes = []): A
{
$tag = (new A())
->content($content)
->mailto($mail ?? ($content === null ? null : (string) $content));
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
return $tag;
}
Generates a {@see Main} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function main(string|Stringable|int|float|null $content = '', array $attributes = []): Main
{
$tag = new Main();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Map} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function map(string|Stringable|int|float|null $content = '', array $attributes = []): Map
{
$tag = new Map();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Mark} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function mark(string|Stringable|int|float|null $content = '', array $attributes = []): Mark
{
$tag = new Mark();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Meta} tag.
| public static Yiisoft\ | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function meta(array $attributes = []): Meta
{
$tag = new Meta();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a {@see Meter} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function meter(string|Stringable|int|float|null $content = '', array $attributes = []): Meter
{
$tag = new Meter();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a normal HTML tag.
See also Yiisoft\
| public static Yiisoft\ | ||
| $name | string |
The tag name. |
| $content | string|\ |
The tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function normalTag(string $name, string|Stringable|int|float|null $content = '', array $attributes = []): CustomTag
{
$tag = (new CustomTag($name))->normal();
if ($content !== '') {
$tag = $tag->content($content);
}
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Normalize PCRE regular expression to use in the "pattern" HTML attribute:
- convert \
For example:
Html::normalizeRegexpPattern('/([a-z0-9-]+)/im'); // will return: ([a-z0-9-]+)
| public static string normalizeRegexpPattern ( string $regexp, string|null $delimiter = null ) | ||
| $regexp | string |
PCRE regular expression. It must be valid UTF-8 string. |
| $delimiter | string|null |
Regular expression delimiter. |
| return | string |
Value for use in the "pattern" HTML attribute |
|---|---|---|
| throws | InvalidArgumentException |
if incorrect regular expression or delimiter |
public static function normalizeRegexpPattern(string $regexp, ?string $delimiter = null): string
{
if (strlen($regexp) < 2) {
throw new InvalidArgumentException('Incorrect regular expression.');
}
/**
* @var string $pattern We assume that `$regexp` is valid UTF-8 string, so `preg_replace()` never returns
* `null`.
*/
$pattern = preg_replace('/\\\\x{?([0-9a-fA-F]+)}?/' , '\u$1' , $regexp);
if ($delimiter === null) {
$delimiter = substr($pattern, 0, 1);
} elseif (strlen($delimiter) !== 1) {
throw new InvalidArgumentException('Incorrect delimiter.');
}
$endPosition = strrpos($pattern, $delimiter, 1);
if ($endPosition === false) {
throw new InvalidArgumentException('Incorrect regular expression.');
}
return substr($pattern, 1, $endPosition - 1);
}
Generates a {@see Noscript} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
public static function noscript(string|Stringable|int|float|null $content = ''): Noscript
{
$tag = new Noscript();
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see ObjectTag} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function object(string|Stringable|int|float|null $content = '', array $attributes = []): ObjectTag
{
$tag = new ObjectTag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Ol} tag.
| public static Yiisoft\ | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function ol(array $attributes = []): Ol
{
$tag = new Ol();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a start tag.
See also \
| public static string openTag ( string $name, array $attributes = [] ) | ||
| $name | string |
The tag name. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function openTag(string $name, array $attributes = []): string
{
return '<' . $name . self::renderTagAttributes($attributes) . '>';
}
Generates a {@see Optgroup} tag.
| public static Yiisoft\ |
public static function optgroup(): Optgroup
{
return new Optgroup();
}
Generates a {@see Option} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $value | boolean|float|integer|string|\ |
The value attribute. |
public static function option(
string|Stringable|int|float|null $content = '',
bool|float|int|string|Stringable|null $value = null,
): Option {
$tag = new Option();
if ($content !== '') {
$tag = $tag->content($content);
}
if ($value !== null) {
$tag = $tag->value($value);
}
return $tag;
}
Generates a {@see Output} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function output(string|Stringable|int|float|null $content = '', array $attributes = []): Output
{
$tag = new Output();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see P} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function p(string|Stringable|int|float|null $content = '', array $attributes = []): P
{
$tag = new P();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a password input field.
See also Yiisoft\
| public static Yiisoft\ | ||
| $name | string|null |
The name attribute. |
| $value | boolean|float|integer|string|\ |
The value attribute. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function passwordInput(
?string $name = null,
bool|float|int|string|Stringable|null $value = null,
array $attributes = [],
): Input {
$tag = Input::password($name, $value);
return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}
Generates a {@see Picture} tag.
| public static Yiisoft\ |
public static function picture(): Picture
{
return new Picture();
}
Generates a {@see Pre} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. If content includes HTML tags or special characters like |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function pre(string|Stringable|int|float|null $content = '', array $attributes = []): Pre
{
$tag = new Pre();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Progress} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function progress(string|Stringable|int|float|null $content = '', array $attributes = []): Progress
{
$tag = new Progress();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Q} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function q(string|Stringable|int|float|null $content = '', array $attributes = []): Q
{
$tag = new Q();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a radio button {@see Input}.
See also Yiisoft\
| public static Yiisoft\ | ||
| $name | string|null |
The name attribute. |
| $value | boolean|float|integer|string|\ |
The value attribute. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function radio(
?string $name = null,
bool|float|int|string|Stringable|null $value = null,
array $attributes = [],
): Radio {
$tag = Input::radio($name, $value);
return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}
Generates a list of radio buttons.
See also Yiisoft\
| public static Yiisoft\ | ||
| $name | string | |
public static function radioList(string $name): RadioList
{
return new RadioList($name);
}
Generates a range {@see Range}.
See also Yiisoft\
| public static Yiisoft\ | ||
| $name | string|null |
The name attribute. |
| $value | float|integer|string|\ |
The value attribute. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function range(
?string $name = null,
float|int|string|Stringable|null $value = null,
array $attributes = [],
): Range {
$tag = Input::range($name, $value);
return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}
Removes a CSS class from the specified attributes.
See also addCssClass().
| public static void removeCssClass ( array &$attributes, string|string[] $class ) | ||
| $attributes | array |
The attributes to be modified. |
| $class | string|string[] |
The CSS class(es) to be removed. |
public static function removeCssClass(array &$attributes, string|array $class): void
{
if (isset($attributes['class'])) {
if (is_array($attributes['class'])) {
$classes = array_diff($attributes['class'], (array) $class);
if (empty($classes)) {
unset($attributes['class']);
} else {
$attributes['class'] = $classes;
}
} else {
/** @var string[] */
$classes = preg_split('/\s+/' , (string) $attributes['class'], -1, PREG_SPLIT_NO_EMPTY);
$classes = array_diff($classes, (array) $class);
if (empty($classes)) {
unset($attributes['class']);
} else {
$attributes['class'] = implode(' ', $classes);
}
}
}
}
Removes the specified CSS styles from the HTML attributes.
For example,
Html::removeCssStyle($attributes, ['width', 'height']);
See also addCssStyle().
| public static void removeCssStyle ( array &$attributes, string|string[] $properties ) | ||
| $attributes | array |
The HTML attributes to be modified. |
| $properties | string|string[] |
The CSS properties to be removed. You may use a string if you are removing a single property. |
public static function removeCssStyle(array &$attributes, string|array $properties): void
{
if (!empty($attributes['style'])) {
/** @psalm-var array<string,string>|string $attributes['style'] */
$style = is_array($attributes['style']) ? $attributes['style'] : self::cssStyleToArray($attributes['style']);
foreach ((array) $properties as $property) {
unset($style[$property]);
}
$attributes['style'] = self::cssStyleFromArray($style);
}
}
Renders the HTML tag attributes.
Attributes whose values are of boolean type will be treated as boolean attributes.
Attributes whose values are null will not be rendered. The values of attributes will be HTML-encoded using
{@see \
The "data" attribute is specially handled when it is receiving an array value. In this case, the array will be
"expanded" and a list data attributes will be rendered. For example, if 'data' => ['id' => 1, 'name' => 'yii']
then this will be rendered data-id="1" data-name="yii".
Additionally, 'data' => ['params' => ['id' => 1, 'name' => 'yii'], 'status' => 'ok'] will be rendered as:
data-params='{"id":1,"name":"yii"}' data-status="ok".
| public static string renderTagAttributes ( array $attributes ) | ||
| $attributes | array |
Attributes to be rendered. The attribute values will be HTML-encoded using
{@see \ |
| return | string |
The rendering result. If the attributes are not empty, they will be rendered into a string with a leading white space (so that it can be directly appended to the tag name in a tag). If there is no attribute, an empty string will be returned. |
|---|---|---|
| throws | JsonException | |
public static function renderTagAttributes(array $attributes): string
{
$html = '';
/**
* @var string $name
*/
foreach ($attributes as $name => $value) {
if (is_bool($value)) {
if ($value) {
$html .= self::renderAttribute($name);
}
} elseif (is_array($value)) {
if (in_array($name, self::DATA_ATTRIBUTES, true)) {
/** @psalm-var array<array-key, scalar[]|string|Stringable|null> $value */
foreach ($value as $n => $v) {
if (!isset($v)) {
continue;
}
$fullName = "$name-$n";
if (in_array($fullName, self::ATTRIBUTES_WITH_CONCATENATED_VALUES, true)) {
$html .= self::renderAttribute(
$fullName,
self::encodeAttribute(
is_array($v) ? implode(' ', $v) : $v,
),
);
} else {
$html .= is_array($v)
? self::renderAttribute($fullName, Json::htmlEncode($v), '\'')
: self::renderAttribute($fullName, self::encodeAttribute($v));
}
}
} elseif (in_array($name, self::ATTRIBUTES_WITH_CONCATENATED_VALUES, true)) {
/** @var string[] $value */
if (empty($value)) {
continue;
}
$html .= self::renderAttribute($name, self::encodeAttribute(implode(' ', $value)));
} elseif ($name === 'style') {
/** @psalm-var array<string,string> $value */
if (empty($value)) {
continue;
}
$html .= self::renderAttribute($name, self::encodeAttribute(self::cssStyleFromArray($value)));
} else {
$html .= self::renderAttribute($name, Json::htmlEncode($value), '\'');
}
} elseif ($value !== null) {
$html .= self::renderAttribute($name, self::encodeAttribute($value));
}
}
return $html;
}
Generates a reset button tag.
See also Yiisoft\
| public static Yiisoft\ | ||
| $content | string|\ |
The content enclosed within the button tag. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function resetButton(string|Stringable|int|float|null $content = 'Reset', array $attributes = []): Button
{
$tag = Button::reset($content);
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
return $tag;
}
Generates a reset {@see Input} button.
See also Yiisoft\
| public static Yiisoft\ | ||
| $label | string|null |
The value attribute. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function resetInput(?string $label = 'Reset', array $attributes = []): Input
{
$tag = Input::resetButton($label);
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
return $tag;
}
Generates a {@see Rp} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function rp(string|Stringable|int|float|null $content = '', array $attributes = []): Rp
{
$tag = new Rp();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Rt} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function rt(string|Stringable|int|float|null $content = '', array $attributes = []): Rt
{
$tag = new Rt();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Ruby} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function ruby(string|Stringable|int|float|null $content = '', array $attributes = []): Ruby
{
$tag = new Ruby();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see S} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function s(string|Stringable|int|float|null $content = '', array $attributes = []): S
{
$tag = new S();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Samp} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function samp(string|Stringable|int|float|null $content = '', array $attributes = []): Samp
{
$tag = new Samp();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Script} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
The script content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function script(string|Stringable $content = '', array $attributes = []): Script
{
$tag = new Script();
if ($content !== '') {
$tag = $tag->content($content);
}
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a {@see Search} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function search(string|Stringable|int|float|null $content = '', array $attributes = []): Search
{
$tag = new Search();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Section} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function section(string|Stringable|int|float|null $content = '', array $attributes = []): Section
{
$tag = new Section();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Select} tag.
| public static Yiisoft\ | ||
| $name | string|null |
The name attribute |
public static function select(?string $name = null): Select
{
$tag = new Select();
if ($name !== null) {
$tag = $tag->name($name);
}
return $tag;
}
Generates a {@see Slot} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function slot(string|Stringable|int|float|null $content = '', array $attributes = []): Slot
{
$tag = new Slot();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Small} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function small(string|Stringable|int|float|null $content = '', array $attributes = []): Small
{
$tag = new Small();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Source} tag.
| public static Yiisoft\ |
public static function source(): Source
{
return new Source();
}
Generates a {@see Span} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function span(string|Stringable|int|float|null $content = '', array $attributes = []): Span
{
$tag = new Span();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Strong} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function strong(string|Stringable|int|float|null $content = '', array $attributes = []): Strong
{
$tag = new Strong();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Style} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
The style content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function style(string|Stringable $content = '', array $attributes = []): Style
{
$tag = new Style();
if ($content !== '') {
$tag = $tag->content($content);
}
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a {@see Sub} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function sub(string|Stringable|int|float|null $content = '', array $attributes = []): Sub
{
$tag = new Sub();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a submit button tag.
See also Yiisoft\
| public static Yiisoft\ | ||
| $content | string|\ |
The content enclosed within the button tag. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function submitButton(string|Stringable|int|float|null $content = 'Submit', array $attributes = []): Button
{
$tag = Button::submit($content);
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
return $tag;
}
Generates submit {@see Input} button.
See also Yiisoft\
| public static Yiisoft\ | ||
| $label | string|null |
The value attribute. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function submitInput(?string $label = 'Submit', array $attributes = []): Input
{
$tag = Input::submitButton($label);
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
return $tag;
}
Generates a {@see Summary} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function summary(string|Stringable|int|float|null $content = '', array $attributes = []): Summary
{
$tag = new Summary();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Sup} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function sup(string|Stringable|int|float|null $content = '', array $attributes = []): Sup
{
$tag = new Sup();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Table} tag.
| public static Yiisoft\ | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function table(array $attributes = []): Table
{
$tag = new Table();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a complete HTML tag.
See also Yiisoft\
| public static Yiisoft\ | ||
| $name | string |
The tag name. |
| $content | string|\ |
The tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function tag(string $name, string|Stringable|int|float|null $content = '', array $attributes = []): CustomTag
{
$tag = new CustomTag($name);
if ($content !== '') {
$tag = $tag->content($content);
}
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a {@see Tbody} tag.
| public static Yiisoft\ | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function tbody(array $attributes = []): Tbody
{
$tag = new Tbody();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a {@see Td} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function td(string|Stringable|int|float|null $content = '', array $attributes = []): Td
{
$tag = new Td();
if ($content !== '') {
$tag = $tag->content($content);
}
if ($attributes !== []) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a {@see Template} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function template(string|Stringable|int|float|null $content = '', array $attributes = []): Template
{
$tag = new Template();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a text {@see Input} field.
| public static Yiisoft\ | ||
| $name | string|null |
The name attribute. |
| $value | boolean|float|integer|string|\ |
The value attribute. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function textInput(
?string $name = null,
bool|float|int|string|Stringable|null $value = null,
array $attributes = [],
): Input {
$tag = Input::text($name, $value);
return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}
Generates a {@see Textarea} input.
| public static Yiisoft\ | ||
| $name | string|null |
The input name. |
| $value | string|string[]|\ |
The input value. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function textarea(?string $name = null, string|Stringable|array|null $value = null, array $attributes = []): Textarea
{
$tag = new Textarea();
if ($name !== null) {
$tag = $tag->name($name);
}
if (!empty($value)) {
$tag = $tag->value($value);
}
return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}
Generates a {@see Tfoot} tag.
| public static Yiisoft\ | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function tfoot(array $attributes = []): Tfoot
{
$tag = new Tfoot();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a {@see Th} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function th(string|Stringable|int|float|null $content = '', array $attributes = []): Th
{
$tag = new Th();
if ($content !== '') {
$tag = $tag->content($content);
}
if ($attributes !== []) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a {@see Thead} tag.
| public static Yiisoft\ | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function thead(array $attributes = []): Thead
{
$tag = new Thead();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a {@see Time} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function time(string|Stringable|int|float|null $content = '', array $attributes = []): Time
{
$tag = new Time();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Title} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function title(string|Stringable|int|float|null $content = '', array $attributes = []): Title
{
$tag = new Title();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Tr} tag.
| public static Yiisoft\ | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function tr(array $attributes = []): Tr
{
$tag = new Tr();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a {@see Track} tag.
| public static Yiisoft\ | ||
| $src | ?string | |
public static function track(?string $src = null): Track
{
$tag = new Track();
return $src === null ? $tag : $tag->src($src);
}
Generates a {@see U} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function u(string|Stringable|int|float|null $content = '', array $attributes = []): U
{
$tag = new U();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Ul} tag.
| public static Yiisoft\ | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function ul(array $attributes = []): Ul
{
$tag = new Ul();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a {@see VarTag} tag.
| public static Yiisoft\ | ||
| $content | string|\ |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function var(string|Stringable|int|float|null $content = '', array $attributes = []): VarTag
{
$tag = new VarTag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a {@see Video} tag.
| public static Yiisoft\ |
public static function video(): Video
{
return new Video();
}
Generates a void HTML tag.
See also Yiisoft\
| public static Yiisoft\ | ||
| $name | string |
The tag name. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function voidTag(string $name, array $attributes = []): CustomTag
{
$tag = (new CustomTag($name))->void();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a {@see Wbr} tag.
| public static Yiisoft\ |
public static function wbr(): Wbr
{
return new Wbr();
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.