### Install Ui Awesome Extension (Bash)
Source: https://github.com/yii2-framework/ui-awesome/blob/main/README.md
This snippet shows the Composer command to install the Ui Awesome extension for Yii2. It assumes you have Composer installed and are running the command in your project's root directory.
```bash
composer require github_username/github_repository-name
```
--------------------------------
### Manage Language and Accessibility Attributes in Yii2 UI
Source: https://context7.com/yii2-framework/ui-awesome/llms.txt
Provides built-in support for internationalization (language) and accessibility (ARIA, role, tabindex) attributes, following WCAG standards. Examples show setting language and complex ARIA attributes.
```php
use yii\ui\html\flow\Div;
// Language attribute
$div = Div::tag()
->lang('es')
->content('Hola Mundo')
->render();
// Output:
// Hola Mundo
//
// Combined accessibility attributes
$button = Div::tag()
->id('dialog-close')
->attributes([
'role' => 'button',
'aria' => [
'label' => 'Close dialog',
'pressed' => 'false'
],
'tabindex' => 0
])
->content('✕')
->render();
// Output:
// ✕
//
// Hidden elements for screen readers
$div = Div::tag()
->attributes(['aria' => ['hidden' => 'true']])
->content('Decorative content')
->render();
```
--------------------------------
### Configure Tag Instances with Defaults in Yii2 UI
Source: https://context7.com/yii2-framework/ui-awesome/llms.txt
Demonstrates how to instantiate HTML tags with default configurations that merge with global factory defaults using Yii2 UI. Shows overriding global defaults with instance-specific settings.
```php
use yii\ui\html\flow\Div;
use yii\ui\factory\SimpleFactory;
// Set global defaults
SimpleFactory::setDefaults(Div::class, [
'class' => 'global-class',
'data' => ['source' => 'global']
]);
// Pass defaults during instantiation
$div = Div::tag([
'id' => 'instance-id',
'class' => 'instance-class',
'title' => 'Instance title'
])->render();
// User defaults override global defaults for class
// Output:
//
// Combine instance defaults with method calls
$div = Div::tag(['class' => 'base'])
->id('custom')
->content('Hello')
->render();
// Output:
// Hello
//
// Instance defaults with nested structures
$div = Div::tag([
'data' => ['level' => 1],
'style' => ['color' => 'blue']
])
->dataAttributes(['extra' => 'value'])
->render();
// Clean up
SimpleFactory::setDefaults(Div::class, []);
```
--------------------------------
### Begin/End Tag Pairs for Nested Content
Source: https://context7.com/yii2-framework/ui-awesome/llms.txt
The `Html::begin()` and `Html::end()` methods facilitate the progressive generation of HTML, allowing for complex nested structures like divs, sections, lists, and even complete HTML documents.
```APIDOC
## POST /yii2-framework/ui-awesome/html::beginEnd
### Description
Enables progressive HTML generation for complex nested structures by opening and closing HTML tags.
### Method
POST (or conceptually, static method calls in PHP)
### Endpoint
Not applicable for static methods, but represents the functions `yii\ui\html\Html::begin()` and `yii\ui\html\Html::end()`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None (These are static method calls).
**Method Signatures:**
`Html::begin(string $tag, array $attributes = []): string`
`Html::end(string $tag): string`
- **tag** (string) - Required - The HTML tag name or a constant representing the tag type (e.g., `Block::DIV`, `Lists::UL`).
- **attributes** (array) - Optional (for `begin()`) - An associative array of HTML attributes for the opening tag.
### Request Example
```php
use yii\ui\html\Html;
use yii\ui\tag\Block;
use yii\ui\tag\Lists;
// Create nested block elements
echo Html::begin(Block::DIV, ['class' => 'container']);
echo Html::begin(Block::SECTION, ['id' => 'main']);
echo 'Content here';
echo Html::end(Block::SECTION);
echo Html::end(Block::DIV);
// Build lists dynamically
echo Html::begin(Lists::UL, ['class' => 'menu']);
foreach (['Home', 'About', 'Contact'] as $item) {
echo Html::begin(Lists::LI);
echo $item;
echo Html::end(Lists::LI);
}
echo Html::end(Lists::UL);
```
### Response
#### Success Response (200)
- **string** (string) - The rendered HTML string representing the opening or closing tag.
#### Response Example
```html
```
```
--------------------------------
### Building HTML Elements with Fluent Tag Classes (PHP)
Source: https://context7.com/yii2-framework/ui-awesome/llms.txt
Demonstrates how to use object-oriented tag classes in PHP to create HTML elements with fluent interfaces. Supports chaining attribute methods, using begin/end for structural tags, and nesting elements. Immutability is a key feature, ensuring configurations are not altered after creation.
```php
use yii\ui\html\flow\Div;
use yii\ui\html\phrasing\Span;
// Create a div with fluent methods
$div = Div::tag()
->class('container')
->id('main')
->content('Hello World')
->render();
// Output:
Hello World
// Chain multiple attribute methods
$styledDiv = Div::tag()
->class('card')
->style('padding: 20px; margin: 10px;')
->dataAttributes(['role' => 'panel', 'id' => 123])
->title('Information Card')
->content('Card content
')
->render();
// Output:
// Use begin/end with tag objects
echo Div::tag()->class('wrapper')->begin();
echo Span::tag()->content('Inner content')->render();
echo 'More content';
echo Div::end();
// Output:
Inner content
More content
// Nested tag objects with immutability
$inner = Span::tag()->class('highlight')->content('Important');
$outer = Div::tag()
->class('container')
->content($inner->render())
->render();
```
--------------------------------
### Factory Pattern for Global Defaults and Tag Instantiation (PHP)
Source: https://context7.com/yii2-framework/ui-awesome/llms.txt
Illustrates the `SimpleFactory` class in PHP for managing global configurations and instantiating tags. It allows setting default attributes for tag classes, which are inherited by new instances. User-provided attributes can override these defaults. The factory also supports dynamic configuration of tag instances.
```php
use yii\ui\factory\SimpleFactory;
use yii\ui\html\flow\Div;
// Set global defaults for a tag class
SimpleFactory::setDefaults(Div::class, [
'class' => 'default-container',
'data' => ['component' => 'ui']
]);
// All new instances inherit defaults
$div1 = Div::tag()->render();
// Output:
$div2 = Div::tag()->id('custom')->render();
// Output:
// User attributes override global defaults
$div3 = Div::tag(['class' => 'override'])->render();
// Output:
// Retrieve current defaults
$defaults = SimpleFactory::getDefaults(Div::class);
// Returns: ['class' => 'default-container', 'data' => ['component' => 'ui']]
// Configure a tag instance dynamically
$configured = SimpleFactory::configure(
Div::tag(),
[
'id' => 'dynamic',
'class' => ['card', 'shadow'],
'content' => 'Dynamic content'
]
);
echo $configured->render();
// Output:
Dynamic content
// Clear defaults
SimpleFactory::setDefaults(Div::class, []);
```
--------------------------------
### Static HTML Element Rendering
Source: https://context7.com/yii2-framework/ui-awesome/llms.txt
The `Html::element()` method allows for quick rendering of any HTML element, supporting automatic content encoding and attribute processing for security and flexibility.
```APIDOC
## POST /yii2-framework/ui-awesome/html::element
### Description
Renders any HTML element with automatic content encoding and attribute processing.
### Method
POST (or conceptually, a static method call in PHP)
### Endpoint
Not applicable for static methods, but represents the function `yii\ui\html\Html::element()`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None (This is a static method call, parameters are passed directly to the method).
**Method Signature:**
`Html::element(string $tag, string $content = '', array $attributes = [], bool $encode = false): string`
- **tag** (string) - Required - The HTML tag name or a constant representing the tag type (e.g., `Block::DIV`).
- **content** (string) - Optional - The content of the HTML element. Defaults to an empty string.
- **attributes** (array) - Optional - An associative array of HTML attributes for the element. Can include class names as arrays, data attributes, and ARIA attributes. Defaults to an empty array.
- **encode** (bool) - Optional - Whether to encode the content to prevent XSS attacks. Defaults to `false`.
### Request Example
```php
use yii\ui\html\Html;
use yii\ui\tag\Block;
// Render a div with raw HTML content
$html = Html::element(Block::DIV, 'Test Content', ['class' => 'test-class']);
// Render with encoded content for security
$html = Html::element(Block::DIV, '', ['class' => 'safe'], true);
```
### Response
#### Success Response (200)
- **string** (string) - The rendered HTML string.
#### Response Example
```html
Test Content
<script>alert("XSS")</script>
```
```
--------------------------------
### Begin/End Tag Pairs for Nested HTML with Yii2 UI Awesome
Source: https://context7.com/yii2-framework/ui-awesome/llms.txt
Enables progressive HTML generation for complex nested structures using begin and end tag methods. Ideal for building dynamic forms, lists, and complete HTML documents.
```php
use yii\ui\html\Html;
use yii\ui\tag\Block;
use yii\ui\tag\Lists;
use yii\ui\tag\Table;
use yii\ui\tag\Root;
// Create nested block elements
echo Html::begin(Block::DIV, ['class' => 'container']);
echo Html::begin(Block::SECTION, ['id' => 'main']);
echo 'Content here';
echo Html::end(Block::SECTION);
echo Html::end(Block::DIV);
// Output:
// Build lists dynamically
echo Html::begin(Lists::UL, ['class' => 'menu']);
foreach (['Home', 'About', 'Contact'] as $item) {
echo Html::begin(Lists::LI);
echo $item;
echo Html::end(Lists::LI);
}
echo Html::end(Lists::UL);
// Create complete HTML documents
echo Html::begin(Root::HTML, ['lang' => 'en']);
echo Html::begin(Root::HEAD);
echo 'Page Title';
echo Html::end(Root::HEAD);
echo Html::begin(Root::BODY);
echo 'Body content';
echo Html::end(Root::BODY);
echo Html::end(Root::HTML);
```
--------------------------------
### Inline Element Rendering with Yii2 UI Awesome
Source: https://context7.com/yii2-framework/ui-awesome/llms.txt
Optimizes rendering for inline-level HTML elements without adding line breaks. Supports content encoding for security and allows for multiple attributes.
```php
use yii\ui\html\Html;
use yii\ui\tag\Inline;
// Render inline elements without encoding
$link = Html::inline(Inline::A, 'Click Here', ['href' => '/page', 'class' => 'btn']);
// Output: Click Here
// Render with content encoding
$code = Html::inline(Inline::CODE, '', ['class' => 'safe'], true);
// Output:
<script>alert("XSS")</script>
// Render inline elements
$span = Html::element(Inline::SPAN, 'inline content', ['id' => 'inline']);
// Output: inline content
// Render void elements (self-closing tags)
$img = Html::element(Voids::IMG, '', [
'class' => ['profile', 'rounded'],
'data' => ['role' => 'avatar', 'id' => 42]
]);
// Output:
```
--------------------------------
### Inline Element Rendering
Source: https://context7.com/yii2-framework/ui-awesome/llms.txt
The `Html::inline()` method is optimized for rendering inline-level HTML elements without introducing unwanted line breaks. It supports content encoding for security.
```APIDOC
## POST /yii2-framework/ui-awesome/html::inline
### Description
Optimizes rendering for inline-level elements without line breaks, with optional content encoding.
### Method
POST (or conceptually, a static method call in PHP)
### Endpoint
Not applicable for static methods, but represents the function `yii\ui\html\Html::inline()`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None (This is a static method call).
**Method Signature:**
`Html::inline(string $tag, string $content = '', array $attributes = [], bool $encode = false): string`
- **tag** (string) - Required - The HTML tag name or a constant representing the inline tag type (e.g., `Inline::SPAN`, `Inline::CODE`).
- **content** (string) - Optional - The content of the inline element. Defaults to an empty string.
- **attributes** (array) - Optional - An associative array of HTML attributes for the element.
- **encode** (bool) - Optional - Whether to encode the content for security. Defaults to `false`.
### Request Example
```php
use yii\ui\html\Html;
use yii\ui\tag\Inline;
// Render inline elements without encoding
$link = Html::inline(Inline::A, 'Click Here', ['href' => '/page', 'class' => 'btn']);
// Render with content encoding
$code = Html::inline(Inline::CODE, '',
'data' => ['value' => '">']
]);
// Output: title="<script>alert("XSS")</script>" data-value=""><script>evil()</script>"
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.