Browse Source

Added "submenuTemplate" property for "items" config in Menu widget

fixes #5681
close #5897
tags/2.0.3
Artem Belov 10 years ago committed by Carsten Brandt
parent
commit
81bcd116a8
  1. 1
      framework/CHANGELOG.md
  2. 8
      framework/widgets/Menu.php

1
framework/CHANGELOG.md

@ -27,6 +27,7 @@ Yii Framework 2 Change Log
- Enh #3723: `yii\filters\PageCache` now supports caching response headers as well as non-HTML response content (qiangxue)
- Enh #4710: Added `yii\web\AssetManager::appendTimestamp` to support cache busting for assets (qiangxue)
- Enh #5663: Added support for using `data-params` to specify additional form data to be submitted via the `data-method` approach (usualdesigner, qiangxue)
- Enh #5681: Allow customization of Menu::submenuTemplate in menu items (RobertBoes, otsec)
- Enh #6106: Added ability to specify `encode` for each item of `yii\widgets\Breadcrumbs` (samdark, aleksanderd)
- Enh #6361: Added `validateAttribute()` to `yii.activeForm.js` to support manually triggering data validation of an input (Alex-Code, qiang)
- Enh #6493: Added support for the `Access-Control-Expose-Headers` header by `yii\filters\Cors` (usualdesigner)

8
framework/widgets/Menu.php

@ -68,6 +68,9 @@ class Menu extends Widget
* The token `{url}` will be replaced by the URL associated with this menu item,
* and the token `{label}` will be replaced by the label of the menu item.
* If this option is not set, [[linkTemplate]] or [[labelTemplate]] will be used instead.
* - submenuTemplate: string, optional, the template used to render the list of sub-menus.
* The token `{items}` will be replaced with the rendered sub-menu items.
* If this option is not set, [[submenuTemplate]] will be used instead.
* - options: array, optional, the HTML attributes for the menu container tag.
*/
public $items = [];
@ -96,7 +99,7 @@ class Menu extends Widget
public $labelTemplate = '{label}';
/**
* @var string the template used to render a list of sub-menus.
* In this template, the token `{items}` will be replaced with the renderer sub-menu items.
* In this template, the token `{items}` will be replaced with the rendered sub-menu items.
*/
public $submenuTemplate = "\n<ul>\n{items}\n</ul>\n";
/**
@ -208,7 +211,8 @@ class Menu extends Widget
$menu = $this->renderItem($item);
if (!empty($item['items'])) {
$menu .= strtr($this->submenuTemplate, [
$submenuTemplate = ArrayHelper::getValue($item, 'submenuTemplate', $this->submenuTemplate);
$menu .= strtr($submenuTemplate, [
'{items}' => $this->renderItems($item['items']),
]);
}

Loading…
Cancel
Save