From 6637bc241f25e35febab831d5ab919e3f45eb7bd Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Fri, 29 May 2015 15:55:34 +0300 Subject: [PATCH] Added docs about array-style CSS classes specification --- docs/guide/helper-html.md | 48 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/guide/helper-html.md b/docs/guide/helper-html.md index 4838d3aa8f..64ae237835 100644 --- a/docs/guide/helper-html.md +++ b/docs/guide/helper-html.md @@ -75,7 +75,53 @@ echo Html::tag('div', 'Pwede na', $options); //
Pwede na
``` -In order to do the same with styles for the `style` attribute: +You may specify multiple CSS classes using array style as well: + +```php +$options = ['class' => ['btn', 'btn-default']]; + +echo Html::tag('div', 'Save', $options); // renders `class="btn btn-default"` +``` + +While adding or removing classes you may use array format as well: + +```php +$options = ['class' => 'btn']; + +if ($type === 'success') { + Html::addCssClass($options, ['btn-success', 'btn-lg']); +} + +echo Html::tag('div', 'Save', $options); // renders `class="btn btn-success btn-lg"` +``` + +`Html::addCssClass()` prevents duplicating classes, so you don't need to worry the same class may appear twice: + +```php +$options = ['class' => 'btn btn-default']; + +Html::addCssClass($options, 'btn-default'); // class 'btn-default' is already present + +echo Html::tag('div', 'Save', $options); // renders `class="btn btn-default"` +``` + +If CSS class option is specified via array format, you may use named key to mark logical purpose of some class. +In this case, class, which added using array format under the same array key, will be ignored: + +```php +$options = [ + 'class' => [ + 'btn', + 'theme' => 'btn-default', + ] +]; + +Html::addCssClass($options, ['theme' => 'btn-success']); // 'theme' key is already taken + +echo Html::tag('div', 'Save', $options); // renders `class="btn btn-default"` +``` + +CSS styles can be setup in similar way using `style` attribute: ```php $options = ['style' => ['width' => '100px', 'height' => '100px']];