PHP yii\helpers Html::renderTagAttributes Examples
The Yii\helpers\Html::renderTagAttributes function is a helper method in PHP that allows developers to easily generate HTML tag attributes using an associative array. It is part of the Yii Framework’s helpers package.
One example usage of this function is to generate a set of class attributes for a HTML tag. For instance, to create a div element with the classes «article» and «featured», one could write:
use Yii\helpers\Html; $attributes = [ 'class' => 'article featured' ]; echo Html::tag('div', 'Lorem ipsum', $attributes);
Another example usage of renderTagAttributes is to generate inline style attributes. For instance, to create a span element with a custom font size and color, one could write:
use Yii\helpers\Html; $attributes = [ 'style' => 'font-size: 20px; color: red;' ]; echo Html::tag('span', 'Hello world', $attributes);
In summary, the Yii\helpers\Html::renderTagAttributes function is a useful PHP helper method for generating HTML tag attributes from associative arrays. It is part of the Yii Framework’s helpers package.
PHP yii\helpers Html::renderTagAttributes — 28 examples found. These are the top rated real world PHP examples of yii\helpers\Html::renderTagAttributes extracted from open source projects. You can rate examples to help us improve the quality of examples.
/** * Renders the content of a menu item. * Note that the container and the sub-menus are not rendered here. * @param array $item the menu item to be rendered. Please refer to [[items]] to see what data might be in the item. * @return string the rendering result */ protected function renderItem($item) < $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []); if (isset($item['url'])) < $template = ArrayHelper::getValue($item, 'template', $this->linkTemplate); return strtr($template, ['' => Html::encode(Url::to($item['url'])), '' => $item['label'], '' => Html::renderTagAttributes($linkOptions)]); > else < $template = ArrayHelper::getValue($item, 'template', $this->labelTemplate); return strtr($template, ['' => $item['label'], '' => Html::renderTagAttributes($linkOptions)]); > >
public function run() < $id = $this->getId(); if (isset($this->options['id']) and !empty($this->options['id'])) < $id = $this->options['id']; > // if no container is set, it will create one if ($this->containerId === null) < $this->htmlOptions['id'] = 'div-chart' . $id; $this->containerId = $this->htmlOptions['id']; echo 'htmlOptions) . '>'; > $this->registerClientScript($id); >
public function init() < if (!isset($this->options[‘id’])) < $this->_cid = $this->options[‘id’] = ’tilec_’ . $this->getId(); > $collapseTag = ‘collapse’; Html::addCssClass($this->options, ‘box’); Html::addCssClass($this->options, ‘box-solid’); Html::addCssClass($this->options, ‘bg-‘ . $this->type); if ($this->collapse and $this->collapseDefault and !$this->collapse_remember) < Html::addCssClass($this->options, ‘collapsed-box’); > $this->registerJs(); echo ‘
‘) . (!$this->title ? » : ‘
title . ‘
‘) . (!$this->collapse ? » : (!$this->custom_tools ? ‘
‘ : »)) . (!$this->custom_tools ? » : ‘
‘) . ‘
‘) . ‘
public function run() < $boxContent = ob_get_clean(); $boxTitle = $this->title ? strtr($this->titleTemplate, ['' => $this->title]) : ''; Html::addCssClass($this->options, 'box'); if ($this->cssClass) < Html::addCssClass($this->options, $this->cssClass); > if ($this->_hasBody == false) < ob_start(); $this->beginBody(); echo $boxContent; $this->endBody(); $boxContent = ob_get_clean(); > echo strtr($this->template, ['' => Html::renderTagAttributes($this->options), '' => $boxTitle, '' => $boxContent]); >
/** * */ protected function renderItem($item) < return strtr(ArrayHelper::getValue($item, 'template', isset($item['url']) ? $this->linkTemplate : $this->labelTemplate), ['' => isset($item['url']) ? Url::to($item['url']) : null, '' => $item['icon'] === false ? '' : sprintf('defaultIcon)), '' => $item['label'], '' => !empty($item['items']) ? ' ' : '', '' => Html::renderTagAttributes(ArrayHelper::getValue($item, 'linkOptions', []))]); >
/** * Renders a single attribute. * @param array $attribute the specification of the attribute to be rendered. * @param integer $index the zero-based index of the attribute in the [[attributes]] array * @return string the rendering result */ protected function renderAttribute($attribute, $index) < if ($attribute['value'] === '') < return ''; >$template = ArrayHelper::getValue($attribute, 'template', $this->template); if (is_string($template)) < if (isset($attribute['label'])) < return strtr($template, ['' => $attribute['label'], '' => Html::renderTagAttributes($attribute['options']), '' => $attribute['value'], '' => $this->formatter->format($attribute['value'], $attribute['format'])]); > else < return strtr($template, ['' => $this->formatter->format($attribute['value'], $attribute['format'])]); > > else < return call_user_func($template, $attribute, $index, $this); >>
/** * @inheritdoc */ protected function renderItem($item) < $item['badgeOptions'] = isset($item['badgeOptions']) ? $item['badgeOptions'] : []; if (!ArrayHelper::getValue($item, 'badgeOptions.class')) < $bg = isset($item['badgeBgClass']) ? $item['badgeBgClass'] : $this->badgeBgClass; $item['badgeOptions']['class'] = $this->badgeClass . ' ' . $bg; > if (isset($item['items']) && !isset($item['right-icon'])) < $item['right-icon'] = $this->parentRightIcon; > if (isset($item['url'])) < $template = ArrayHelper::getValue($item, 'template', $this->linkTemplate); return strtr($template, ['' => isset($item['badge']) ? Html::tag('small', $item['badge'], $item['badgeOptions']) : '', '' => isset($item['icon']) ? $item['icon'] : '', '' => isset($item['right-icon']) ? $item['right-icon'] : '', '' => Url::to($item['url']), '' => $item['label'], '' => isset($item['linkOptions']) ? Html::renderTagAttributes($item['linkOptions']) : '']); > else < $template = ArrayHelper::getValue($item, 'template', $this->labelTemplate); return strtr($template, ['' => isset($item['badge']) ? Html::tag('small', $item['badge'], $item['badgeOptions']) : '', '' => isset($item['icon']) ? $item['icon'] : '', '' => isset($item['right-icon']) ? $item['right-icon'] : '', '' => $item['label'], '' => isset($item['linkOptions']) ? Html::renderTagAttributes($item['linkOptions']) : '']); > >
/** * Executes the widget. * This method registers all needed client scripts and renders * the text field. */ public function run() < $uploadDir = \Yii::$app->urlManager->baseUrl . '/uploads'; $id = $this->options['id']; if (isset($this->options['name'])) < $name = $this->options['name']; > if ($this->sizeValidate !== array() and isset($this->sizeValidate['width'], $this->sizeValidate['height'])) < $this->width = $this->sizeValidate['width']; $this->height = $this->sizeValidate['height']; $textSmall = strtr($this->templateSmall, array('' => $this->sizeValidate['width'], '' => $this->sizeValidate['height'])); echo ''; > $img = ''; if (!$this->model->isNewRecord and !empty($this->model->attribute>)) < $img = "attribute>>\" alt=\"\">"; > $arrayFile = explode('.', $this->model->attribute>); $ext = end($arrayFile); if (isset($this->iconExtensions[$ext])) < $filenamePreview = $this->iconExtensions[$ext]; $img = "
attribute>>\" target=\"_blank\"> if (isset($this->imgContainerOptions['class'])) < $this->imgContainerOptions['class'] = $this->imgContainerOptions['class'] . " containerCss> _img text-center"; > else < $this->imgContainerOptions['class'] = "containerCss> _img text-center"; > $this->imgContainerOptions['data-url'] = ""; $icon = ""; if ($this->iconButtom !== false) < $icon = " mtl\" style=\"font-size: 10em;color: #f0f0f0\">"; > if (!$this->model->isNewRecord and !empty($this->model->attribute>)) < $icon = ""; >echo "\n imgContainerOptions) . ">\n \n \n\n "; if ($this->hasModel()) < echo Html::activeHiddenInput($this->model, $this->attribute, $this->options); > else < echo Html::hiddenInput($this->name, $this->value, $this->options); > $this->registerClientScript(); >/** * Retrieves Html options * @param string $tag given tag * @param boolean $asString if return as string * @return type */ public static function getHtmlOptions($tag, $options = [], $asString = false)
/** * Renders a single attribute. * @param array $attribute the specification of the attribute to be rendered. * @param integer $index the zero-based index of the attribute in the [[attributes]] array * @return string the rendering result */ protected function renderAttribute($attribute, $index) < if (is_string($this->template)) < $captionOptions = Html::renderTagAttributes(ArrayHelper::getValue($attribute, 'captionOptions', [])); $contentOptions = Html::renderTagAttributes(ArrayHelper::getValue($attribute, 'contentOptions', [])); return strtr($this->template, ['' => $attribute['label'], '' => $this->formatter->format($attribute['value'], $attribute['format']), '' => $captionOptions, '' => $contentOptions]); > else < return call_user_func($this->template, $attribute, $index, $this); > >Translation\backend\assets\ListAssetBundle::register($this); /** * @param string $type * @param string $label * @return string */ function sortLink($type, $label) < $label .= ' ' . FA::icon('sort-numeric-desc', ['ng-show' =>'pages.sort.order === "-' . $type . '"']); $label .= ' ' . FA::icon('sort-numeric-asc', ['ng-show' => 'pages.sort.order === "' . $type . '"']); return Html::a($label, null, ['ng-click' => 'pages.sort.setOrder("' . $type . '")']); > ?> 'content', 'ng-controller' => 'translation.ListController']); ?> >
'checker', 'ng-click' => 'filter.toggleTranslated()', 'ng-class' => Json::encode(['checked' => new \yii\web\JsExpression('filter.translated === true')])]); ?>$title = $application->title; $icon = $application->icon->render(\bedezign\yii2\desktop\Icon::DISPLAY_TITLEBAR); $attributes = ['id' => 'window_' . $application->applicationId, 'class' => 'application_window absolute']; if ($application->windowState) < Html::addCssStyle($attributes, $application->windowState); > if ($application->windowMaximised) < Html::addCssClass($attributes, 'window_maximized'); >if ($application->sessionData) < $attributes['data-desktop-session'] = \yii\helpers\Json::encode($application->sessionData); > ?> > applicationId;/** @var \frontend\components\Controller $controller */ $controller = $this->context; /** @var \resources\Account\Model|null $Account */ $Account = User()->identity; $this->registerLinkTag(['rel' => 'canonical', 'href' => \yii\helpers\Url::canonical()], 'canonical'); $this->registerMetaTag(['charset' => Yii::$app->charset], 'charset'); $this->registerMetaTag(['name' => 'viewport', 'content' => 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'], 'viewport'); if (!User()->isGuest) < $this->registerMetaTag(['name' => 'token', 'content' => $Account->token], 'token'); > rmrevin\yii\favicon\Favicon::widget(['forceGenerate' => true, 'appname' => 'Cookyii CMF', 'color' => '#2B5797', 'fillColor' => '#A4EDFF']); $this->beginPage(); ?> Yii::$app->language, 'ng-app' => 'FrontendApp']); ?> >