Final Class Yiisoft\Html\Html
| Inheritance | Yiisoft\Html\Html |
|---|
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 $options parameter. See the
documentation of the tag() method for more details.
Public Methods
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\Html\Html |
| ATTRIBUTE_ORDER | [ 'type', 'id', 'class', 'name', 'value', 'href', 'loading', 'src', 'srcset', 'form', 'action', 'method', 'selected', 'checked', 'readonly', 'disabled', 'multiple', 'size', 'maxlength', 'minlength', 'width', 'height', 'rows', 'cols', 'alt', 'title', 'rel', 'media', ] | The preferred order of attributes in a tag. This mainly affects the order of the attributes that are rendered by renderTagAttributes(). | Yiisoft\Html\Html |
| 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\Html\Html |
Method Details
Generates a hyperlink tag.
See also Yiisoft\Html\Tag\A.
| public static a( string|\Stringable $content = '', string|null $url = null, array $attributes = [] ): Yiisoft\Html\Tag\A | ||
| $content | string|\Stringable |
The tag content. |
| $url | string|null | |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function a(string|Stringable $content = '', ?string $url = null, array $attributes = []): A
{
$tag = A::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
if ($content !== '') {
$tag = $tag->content($content);
}
if ($url !== null) {
$tag = $tag->url($url);
}
return $tag;
}
Adds a CSS class (or several classes) to the specified options.
If the CSS class is already in the options, it will not be added again. If class specification at given options is an array, and some class placed there with the named (string) key, overriding of such key will have no effect. For example:
$options = ['class' => ['persistent' => 'initial']];
// ['class' => ['persistent' => 'initial']];
Html::addCssClass($options, ['persistent' => 'override']);
See also removeCssClass().
| public static addCssClass( array &$options, \BackedEnum|\BackedEnum[]|null[]|string|string[]|null $class ): void | ||
| $options | array |
The options to be modified. All string values in the array must be valid UTF-8 strings. |
| $class | \BackedEnum|\BackedEnum[]|null[]|string|string[]|null |
The CSS class(es) to be added. Null values will be ignored. |
public static function addCssClass(array &$options, 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 ($value instanceof BackedEnum) {
$value = is_string($value->value) ? $value->value : null;
}
if ($value !== null) {
$filteredClass[$key] = $value;
}
}
if (empty($filteredClass)) {
return;
}
$class = $filteredClass;
}
if (isset($options['class'])) {
if (is_array($options['class'])) {
/** @psalm-var string[] $options['class'] */
$options['class'] = self::mergeCssClasses($options['class'], (array) $class);
} else {
/**
* @psalm-var string $options['class']
* @var string[] $classes We assume that `$options['class']` is valid UTF-8 string, so `preg_split()`
* never returns `false`.
*/
$classes = preg_split('/\s+/', $options['class'], -1, PREG_SPLIT_NO_EMPTY);
$classes = self::mergeCssClasses($classes, (array) $class);
$options['class'] = is_array($class) ? $classes : implode(' ', $classes);
}
} else {
$options['class'] = $class;
}
}
Adds the specified CSS styles to the HTML options.
If the options 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($options, 'width: 100px; height: 200px');
See also removeCssStyle().
| public static addCssStyle( array &$options, string|string[] $style, boolean $overwrite = true ): void | ||
| $options | array |
The HTML options to be modified. |
| $style | string|string[] |
The new style string (e.g. |
| $overwrite | boolean |
Whether to overwrite existing CSS properties if the new style contain them too. |
public static function addCssStyle(array &$options, array|string $style, bool $overwrite = true): void
{
if (!empty($options['style'])) {
/** @psalm-var array<string,string>|string $options['style'] */
$oldStyle = is_array($options['style']) ? $options['style'] : self::cssStyleToArray($options['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);
}
$options['style'] = is_array($style) ? self::cssStyleFromArray($style) : $style;
}
Generates a Yiisoft\Html\Tag\Address tag.
| public static address( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Address | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function address(string|Stringable $content = '', array $attributes = []): Address
{
$tag = Address::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Article tag.
| public static article( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Article | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function article(string|Stringable $content = '', array $attributes = []): Article
{
$tag = Article::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Aside tag.
| public static aside( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Aside | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function aside(string|Stringable $content = '', array $attributes = []): Aside
{
$tag = Aside::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Audio tag.
| public static audio( ): Yiisoft\Html\Tag\Audio |
public static function audio(): Audio
{
return Audio::tag();
}
Generates a Yiisoft\Html\Tag\B tag.
| public static b( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\B | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function b(string|Stringable $content = '', array $attributes = []): B
{
$tag = B::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Body tag.
| public static body( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Body | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function body(string|Stringable $content = '', array $attributes = []): Body
{
$tag = Body::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Br tag.
| public static br( ): Yiisoft\Html\Tag\Br |
public static function br(): Br
{
return Br::tag();
}
Generates a Yiisoft\Html\Tag\Caption tag.
| public static caption( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Caption | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function caption(string|Stringable $content = '', array $attributes = []): Caption
{
$tag = Caption::tag();
if ($content !== '') {
$tag = $tag->content($content);
}
if ($attributes !== []) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a checkbox Yiisoft\Html\Tag\Input.
See also Yiisoft\Html\Tag\Input::checkbox().
| public static checkbox( string|null $name = null, boolean|float|integer|string|\Stringable|null $value = null, array $attributes = [] ): Yiisoft\Html\Tag\Input\Checkbox | ||
| $name | string|null |
The name attribute. |
| $value | boolean|float|integer|string|\Stringable|null |
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 checkboxList( string $name ): Yiisoft\Html\Widget\CheckboxList\CheckboxList | ||
| $name | string | |
public static function checkboxList(string $name): CheckboxList
{
return CheckboxList::create($name);
}
Generates an end tag.
See also \Yiisoft\Html\self::openTag().
| public static closeTag( string $name ): string | ||
| $name | string |
The tag name. |
public static function closeTag(string $name): string
{
return "</$name>";
}
Generates a Yiisoft\Html\Tag\Code tag.
| public static code( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Code | ||
| $content | string|\Stringable |
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 $content = '', array $attributes = []): Code
{
$tag = Code::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Col tag.
| public static col( array $attributes = [] ): Yiisoft\Html\Tag\Col | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function col(array $attributes = []): Col
{
$tag = Col::tag();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a Yiisoft\Html\Tag\Colgroup tag.
| public static colgroup( array $attributes = [] ): Yiisoft\Html\Tag\Colgroup | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function colgroup(array $attributes = []): Colgroup
{
$tag = Colgroup::tag();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a color Yiisoft\Html\Tag\Input field.
See also Yiisoft\Html\Tag\Input::color().
| public static color( string|null $name = null, string|\Stringable|null $value = null, array $attributes = [] ): Yiisoft\Html\Tag\Input\Color | ||
| $name | string|null |
The name attribute. |
| $value | string|\Stringable|null |
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 Yiisoft\Html\Tag\Link tag that refers to an CSS file.
| public static cssFile( string $url, array $attributes = [] ): Yiisoft\Html\Tag\Link | ||
| $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 cssStyleFromArray( array<string, string> $style ): string|null | ||
| $style | array<string, string> |
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 cssStyleToArray( string|\Stringable $style ): array | ||
| $style | string|\Stringable |
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 Yiisoft\Html\Tag\Datalist tag.
| public static datalist( array $attributes = [] ): Yiisoft\Html\Tag\Datalist | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function datalist(array $attributes = []): Datalist
{
$tag = Datalist::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a Yiisoft\Html\Tag\Div tag.
| public static div( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Div | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function div(string|Stringable $content = '', array $attributes = []): Div
{
$tag = Div::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Em tag.
| public static em( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Em | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function em(string|Stringable $content = '', array $attributes = []): Em
{
$tag = Em::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Encodes special characters into HTML entities for use as a tag content
i.e. <div>tag content</div>.
Characters encoded are: &, <, >.
| public static encode( mixed $content, boolean $doubleEncode = true, string $encoding = 'UTF-8' ): string | ||
| $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 encodeAttribute( mixed $value, boolean $doubleEncode = true, string $encoding = 'UTF-8' ): string | ||
| $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 encodeUnquotedAttribute( mixed $value, boolean $doubleEncode = true, string $encoding = 'UTF-8' ): string | ||
| $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 escapeJavaScriptStringValue( mixed $value ): string | ||
| $value | mixed |
JavaScript string. |
| return | string |
Escaped JavaScript string. |
|---|---|---|
public static function escapeJavaScriptStringValue(mixed $value): string
{
return strtr((string) $value, [
'/' => '\/',
'"' => '\"',
"'" => "\'",
'\\' => '\\\\',
]);
}
Generates a Yiisoft\Html\Tag\Fieldset tag.
| public static fieldset( array $attributes = [] ): Yiisoft\Html\Tag\Fieldset | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function fieldset(array $attributes = []): Fieldset
{
$tag = Fieldset::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
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\Html\Tag\Input::file().
| public static file( string|null $name = null, boolean|float|integer|string|\Stringable|null $value = null, array $attributes = [] ): Yiisoft\Html\Tag\Input\File | ||
| $name | string|null |
The name attribute. |
| $value | boolean|float|integer|string|\Stringable|null |
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 Yiisoft\Html\Tag\Form tag.
| public static form( string|null $action = null, string|null $method = null, array $attributes = [] ): Yiisoft\Html\Tag\Form | ||
| $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 = Form::tag();
if ($action !== null) {
$attributes['action'] = $action;
}
if ($method !== null) {
$attributes['method'] = $method;
}
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Returns an autogenerated sequential ID.
| public static generateId( string $prefix = 'i' ): string | ||
| $prefix | string | |
| return | string |
Autogenerated ID. |
|---|---|---|
public static function generateId(string $prefix = 'i'): string
{
$prefix .= hrtime(true);
if (isset(self::$generateIdCounter[$prefix])) {
$counter = ++self::$generateIdCounter[$prefix];
} else {
$counter = 1;
self::$generateIdCounter = [$prefix => $counter];
}
return $prefix . $counter;
}
| public static getArrayableName( string $name ): string | ||
| $name | string | |
public static function getArrayableName(string $name): string
{
return !str_ends_with($name, '[]') ? $name . '[]' : $name;
}
| public static getNonArrayableName( string $name ): string | ||
| $name | string | |
public static function getNonArrayableName(string $name): string
{
return str_ends_with($name, '[]') ? substr($name, 0, -2) : $name;
}
Generates a Yiisoft\Html\Tag\H1 tag.
| public static h1( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\H1 | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function h1(string|Stringable $content = '', array $attributes = []): H1
{
$tag = H1::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\H2 tag.
| public static h2( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\H2 | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function h2(string|Stringable $content = '', array $attributes = []): H2
{
$tag = H2::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\H3 tag.
| public static h3( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\H3 | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function h3(string|Stringable $content = '', array $attributes = []): H3
{
$tag = H3::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\H4 tag.
| public static h4( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\H4 | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function h4(string|Stringable $content = '', array $attributes = []): H4
{
$tag = H4::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\H5 tag.
| public static h5( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\H5 | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function h5(string|Stringable $content = '', array $attributes = []): H5
{
$tag = H5::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\H6 tag.
| public static h6( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\H6 | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function h6(string|Stringable $content = '', array $attributes = []): H6
{
$tag = H6::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Header tag.
| public static header( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Header | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function header(string|Stringable $content = '', array $attributes = []): Header
{
$tag = Header::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Hgroup tag.
| public static hgroup( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Hgroup | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function hgroup(string|Stringable $content = '', array $attributes = []): Hgroup
{
$tag = Hgroup::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Hr tag.
| public static hr( array $attributes = [] ): Yiisoft\Html\Tag\Hr | ||
| $attributes | array | |
public static function hr(array $attributes = []): Hr
{
$tag = Hr::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a Yiisoft\Html\Html tag.
| public static html( string|\Stringable $content = '', string|null $lang = null, array $attributes = [] ): Yiisoft\Html\Tag\Html | ||
| $content | string|\Stringable |
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 $content = '', ?string $lang = null, array $attributes = []): Tag\Html
{
$tag = Tag\Html::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
if ($content !== '') {
$tag = $tag->content($content);
}
if ($lang !== null) {
$tag = $tag->lang($lang);
}
return $tag;
}
Generates a Yiisoft\Html\Tag\I tag.
| public static i( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\I | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function i(string|Stringable $content = '', array $attributes = []): I
{
$tag = I::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates an Yiisoft\Html\Tag\Img tag.
| public static img( string|null $url = null, string|null $alt = '', array $attributes = [] ): Yiisoft\Html\Tag\Img | ||
| $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 = Img::tag();
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 Yiisoft\Html\Tag\Input type of the given type.
| public static input( string $type, string|null $name = null, boolean|float|integer|string|\Stringable|null $value = null, array $attributes = [] ): Yiisoft\Html\Tag\Input | ||
| $type | string |
The type attribute. |
| $name | string|null |
The name attribute. If it is |
| $value | boolean|float|integer|string|\Stringable|null |
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 = Input::tag()->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 Yiisoft\Html\Tag\Script tag that refers to a JavaScript file.
| public static javaScriptFile( string $url, array $attributes = [] ): Yiisoft\Html\Tag\Script | ||
| $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 = Script::tag()->url($url);
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
return $tag;
}
Generates a Yiisoft\Html\Tag\Label tag.
| public static label( string|\Stringable $content = '', string|null $for = null ): Yiisoft\Html\Tag\Label | ||
| $content | string|\Stringable |
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 $content = '', ?string $for = null): Label
{
$tag = Label::tag();
if ($for !== null) {
$tag = $tag->forId($for);
}
if ($content !== '') {
$tag = $tag->content($content);
}
return $tag;
}
Generates a Yiisoft\Html\Tag\Legend tag.
| public static legend( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Legend | ||
| $content | string|\Stringable |
The tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function legend(string|Stringable $content = '', array $attributes = []): Legend
{
$tag = Legend::tag();
if ($content !== '') {
$tag = $tag->content($content);
}
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a Yiisoft\Html\Tag\Li tag.
| public static li( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Li | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function li(string|Stringable $content = '', array $attributes = []): Li
{
$tag = Li::tag();
if ($attributes !== []) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Link tag.
| public static link( string|null $url = null, array $attributes = [] ): Yiisoft\Html\Tag\Link | ||
| $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 = Link::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
if ($url !== null) {
$tag = $tag->url($url);
}
return $tag;
}
Generates a mailto hyperlink tag.
See also Yiisoft\Html\Tag\A.
| public static mailto( string $content, string|null $mail = null, array $attributes = [] ): Yiisoft\Html\Tag\A | ||
| $content | string | |
| string|null | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function mailto(string $content, ?string $mail = null, array $attributes = []): A
{
$tag = A::tag()
->content($content)
->mailto($mail ?? $content);
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
return $tag;
}
Generates a Yiisoft\Html\Tag\Meta tag.
| public static meta( array $attributes = [] ): Yiisoft\Html\Tag\Meta | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function meta(array $attributes = []): Meta
{
$tag = Meta::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a normal HTML tag.
See also Yiisoft\Html\Tag\CustomTag.
| public static normalTag( string $name, string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\CustomTag | ||
| $name | string |
The tag name. |
| $content | string|\Stringable |
The tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function normalTag(string $name, string|Stringable $content = '', array $attributes = []): CustomTag
{
$tag = CustomTag::name($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 \x{FFFF} to \uFFFF; - remove flags and delimiters.
For example:
Html::normalizeRegexpPattern('/([a-z0-9-]+)/im'); // will return: ([a-z0-9-]+)
| public static normalizeRegexpPattern( string $regexp, string|null $delimiter = null ): string | ||
| $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 Yiisoft\Html\Tag\Noscript tag.
| public static noscript( string|\Stringable $content = '' ): Yiisoft\Html\Tag\Noscript | ||
| $content | string|\Stringable |
Tag content. |
public static function noscript(string|Stringable $content = ''): Noscript
{
$tag = Noscript::tag();
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Ol tag.
| public static ol( array $attributes = [] ): Yiisoft\Html\Tag\Ol | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function ol(array $attributes = []): Ol
{
$tag = Ol::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a start tag.
See also \Yiisoft\Html\self::closeTag().
| public static openTag( string $name, array $attributes = [] ): string | ||
| $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 Yiisoft\Html\Tag\Optgroup tag.
| public static optgroup( ): Yiisoft\Html\Tag\Optgroup |
public static function optgroup(): Optgroup
{
return Optgroup::tag();
}
Generates a Yiisoft\Html\Tag\Option tag.
| public static option( string|\Stringable $content = '', boolean|float|integer|string|\Stringable|null $value = null ): Yiisoft\Html\Tag\Option | ||
| $content | string|\Stringable |
Tag content. |
| $value | boolean|float|integer|string|\Stringable|null |
The value attribute. |
public static function option(
string|Stringable $content = '',
bool|float|int|string|Stringable|null $value = null,
): Option {
$tag = Option::tag();
if ($content !== '') {
$tag = $tag->content($content);
}
if ($value !== null) {
$tag = $tag->value($value);
}
return $tag;
}
Generates a Yiisoft\Html\Tag\P tag.
| public static p( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\P | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function p(string|Stringable $content = '', array $attributes = []): P
{
$tag = P::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a password input field.
See also Yiisoft\Html\Tag\Input::password().
| public static passwordInput( string|null $name = null, boolean|float|integer|string|\Stringable|null $value = null, array $attributes = [] ): Yiisoft\Html\Tag\Input | ||
| $name | string|null |
The name attribute. |
| $value | boolean|float|integer|string|\Stringable|null |
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 Yiisoft\Html\Tag\Picture tag.
| public static picture( ): Yiisoft\Html\Tag\Picture |
public static function picture(): Picture
{
return Picture::tag();
}
Generates a Yiisoft\Html\Tag\Pre tag.
| public static pre( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Pre | ||
| $content | string|\Stringable |
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 $content = '', array $attributes = []): Pre
{
$tag = Pre::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a radio button Yiisoft\Html\Tag\Input.
See also Yiisoft\Html\Tag\Input::radio().
| public static radio( string|null $name = null, boolean|float|integer|string|\Stringable|null $value = null, array $attributes = [] ): Yiisoft\Html\Tag\Input\Radio | ||
| $name | string|null |
The name attribute. |
| $value | boolean|float|integer|string|\Stringable|null |
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\Html\Widget\RadioList\RadioList.
| public static radioList( string $name ): Yiisoft\Html\Widget\RadioList\RadioList | ||
| $name | string | |
public static function radioList(string $name): RadioList
{
return RadioList::create($name);
}
Generates a range Yiisoft\Html\Tag\Input\Range.
See also Yiisoft\Html\Tag\Input::range().
| public static range( string|null $name = null, float|integer|string|\Stringable|null $value = null, array $attributes = [] ): Yiisoft\Html\Tag\Input\Range | ||
| $name | string|null |
The name attribute. |
| $value | float|integer|string|\Stringable|null |
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 options.
See also addCssClass().
| public static removeCssClass( array &$options, string|string[] $class ): void | ||
| $options | array |
The options to be modified. |
| $class | string|string[] |
The CSS class(es) to be removed. |
public static function removeCssClass(array &$options, string|array $class): void
{
if (isset($options['class'])) {
if (is_array($options['class'])) {
$classes = array_diff($options['class'], (array) $class);
if (empty($classes)) {
unset($options['class']);
} else {
$options['class'] = $classes;
}
} else {
/** @var string[] */
$classes = preg_split('/\s+/', (string) $options['class'], -1, PREG_SPLIT_NO_EMPTY);
$classes = array_diff($classes, (array) $class);
if (empty($classes)) {
unset($options['class']);
} else {
$options['class'] = implode(' ', $classes);
}
}
}
}
Removes the specified CSS styles from the HTML options.
For example,
Html::removeCssStyle($options, ['width', 'height']);
See also addCssStyle().
| public static removeCssStyle( array &$options, string|string[] $properties ): void | ||
| $options | array |
The HTML options 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 &$options, string|array $properties): void
{
if (!empty($options['style'])) {
/** @psalm-var array<string,string>|string $options['style'] */
$style = is_array($options['style']) ? $options['style'] : self::cssStyleToArray($options['style']);
foreach ((array) $properties as $property) {
unset($style[$property]);
}
$options['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 encodeAttribute().
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 renderTagAttributes( array $attributes ): string | ||
| $attributes | array |
Attributes to be rendered. The attribute values will be HTML-encoded using encodeAttribute(). |
| 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
{
if (count($attributes) > 1) {
$sorted = [];
foreach (self::ATTRIBUTE_ORDER as $name) {
if (isset($attributes[$name])) {
$sorted[$name] = $attributes[$name];
}
}
$attributes = array_merge($sorted, $attributes);
}
$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\Html\Tag\Button::reset().
| public static resetButton( string $content = 'Reset', array $attributes = [] ): Yiisoft\Html\Tag\Button | ||
| $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 $content = 'Reset', array $attributes = []): Button
{
$tag = Button::reset($content);
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
return $tag;
}
Generates a reset Yiisoft\Html\Tag\Input button.
See also Yiisoft\Html\Tag\Input::resetButton().
| public static resetInput( string|null $label = 'Reset', array $attributes = [] ): Yiisoft\Html\Tag\Input | ||
| $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 Yiisoft\Html\Tag\Script tag.
| public static script( string $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Script | ||
| $content | string |
The script content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function script(string $content = '', array $attributes = []): Script
{
$tag = Script::tag();
if ($content !== '') {
$tag = $tag->content($content);
}
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a Yiisoft\Html\Tag\Section tag.
| public static section( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Section | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function section(string|Stringable $content = '', array $attributes = []): Section
{
$tag = Section::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Select tag.
| public static select( string|null $name = null ): Yiisoft\Html\Tag\Select | ||
| $name | string|null |
The name attribute |
public static function select(?string $name = null): Select
{
$tag = Select::tag();
if ($name !== null) {
$tag = $tag->name($name);
}
return $tag;
}
Generates a Yiisoft\Html\Tag\Small tag.
| public static small( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Small | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function small(string|Stringable $content = '', array $attributes = []): Small
{
$tag = Small::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Source tag.
| public static source( ): Yiisoft\Html\Tag\Source |
public static function source(): Source
{
return Source::tag();
}
Generates a Yiisoft\Html\Tag\Span tag.
| public static span( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Span | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function span(string|Stringable $content = '', array $attributes = []): Span
{
$tag = Span::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Strong tag.
| public static strong( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Strong | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function strong(string|Stringable $content = '', array $attributes = []): Strong
{
$tag = Strong::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Style tag.
| public static style( string $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Style | ||
| $content | string |
The style content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function style(string $content = '', array $attributes = []): Style
{
$tag = Style::tag();
if ($content !== '') {
$tag = $tag->content($content);
}
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a submit button tag.
See also Yiisoft\Html\Tag\Button::submit().
| public static submitButton( string $content = 'Submit', array $attributes = [] ): Yiisoft\Html\Tag\Button | ||
| $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 $content = 'Submit', array $attributes = []): Button
{
$tag = Button::submit($content);
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
return $tag;
}
Generates submit Yiisoft\Html\Tag\Input button.
See also Yiisoft\Html\Tag\Input::submitButton().
| public static submitInput( string|null $label = 'Submit', array $attributes = [] ): Yiisoft\Html\Tag\Input | ||
| $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 Yiisoft\Html\Tag\Table tag.
| public static table( array $attributes = [] ): Yiisoft\Html\Tag\Table | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function table(array $attributes = []): Table
{
$tag = Table::tag();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a complete HTML tag.
See also Yiisoft\Html\Tag\CustomTag.
| public static tag( string $name, string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\CustomTag | ||
| $name | string |
The tag name. |
| $content | string|\Stringable |
The tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function tag(string $name, string|Stringable $content = '', array $attributes = []): CustomTag
{
$tag = CustomTag::name($name);
if ($content !== '') {
$tag = $tag->content($content);
}
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a Yiisoft\Html\Tag\Tbody tag.
| public static tbody( array $attributes = [] ): Yiisoft\Html\Tag\Tbody | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function tbody(array $attributes = []): Tbody
{
$tag = Tbody::tag();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a Yiisoft\Html\Tag\Td tag.
| public static td( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Td | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function td(string|Stringable $content = '', array $attributes = []): Td
{
$tag = Td::tag();
if ($content !== '') {
$tag = $tag->content($content);
}
if ($attributes !== []) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a text Yiisoft\Html\Tag\Input field.
| public static textInput( string|null $name = null, boolean|float|integer|string|\Stringable|null $value = null, array $attributes = [] ): Yiisoft\Html\Tag\Input | ||
| $name | string|null |
The name attribute. |
| $value | boolean|float|integer|string|\Stringable|null |
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 Yiisoft\Html\Tag\Textarea input.
| public static textarea( string|null $name = null, string|string[]|\Stringable|null $value = null, array $attributes = [] ): Yiisoft\Html\Tag\Textarea | ||
| $name | string|null |
The input name. |
| $value | string|string[]|\Stringable|null |
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 = Textarea::tag();
if ($name !== null) {
$tag = $tag->name($name);
}
if (!empty($value)) {
$tag = $tag->value($value);
}
return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}
Generates a Yiisoft\Html\Tag\Tfoot tag.
| public static tfoot( array $attributes = [] ): Yiisoft\Html\Tag\Tfoot | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function tfoot(array $attributes = []): Tfoot
{
$tag = Tfoot::tag();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a Yiisoft\Html\Tag\Th tag.
| public static th( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Th | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function th(string|Stringable $content = '', array $attributes = []): Th
{
$tag = Th::tag();
if ($content !== '') {
$tag = $tag->content($content);
}
if ($attributes !== []) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a Yiisoft\Html\Tag\Thead tag.
| public static thead( array $attributes = [] ): Yiisoft\Html\Tag\Thead | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function thead(array $attributes = []): Thead
{
$tag = Thead::tag();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a Yiisoft\Html\Tag\Title tag.
| public static title( string|\Stringable $content = '', array $attributes = [] ): Yiisoft\Html\Tag\Title | ||
| $content | string|\Stringable |
Tag content. |
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function title(string|Stringable $content = '', array $attributes = []): Title
{
$tag = Title::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $content === '' ? $tag : $tag->content($content);
}
Generates a Yiisoft\Html\Tag\Tr tag.
| public static tr( array $attributes = [] ): Yiisoft\Html\Tag\Tr | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function tr(array $attributes = []): Tr
{
$tag = Tr::tag();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
Generates a Yiisoft\Html\Tag\Track tag.
| public static track( string|null $src = null ): Yiisoft\Html\Tag\Track | ||
| $src | string|null | |
public static function track(?string $src = null): Track
{
$tag = Track::tag();
return $src === null ? $tag : $tag->src($src);
}
Generates a Yiisoft\Html\Tag\Ul tag.
| public static ul( array $attributes = [] ): Yiisoft\Html\Tag\Ul | ||
| $attributes | array |
The tag attributes in terms of name-value pairs. |
public static function ul(array $attributes = []): Ul
{
$tag = Ul::tag();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Generates a Yiisoft\Html\Tag\Video tag.
| public static video( ): Yiisoft\Html\Tag\Video |
public static function video(): Video
{
return Video::tag();
}
Generates a void HTML tag.
See also Yiisoft\Html\Tag\CustomTag.
| public static voidTag( string $name, array $attributes = [] ): Yiisoft\Html\Tag\CustomTag | ||
| $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 = CustomTag::name($name)->void();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
return $tag;
}
Signup or Login in order to comment.