mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 06:11:35 +08:00
Added "submenuTemplate" property for "items" config in Menu widget
fixes #5681 close #5897
This commit is contained in:

committed by
Carsten Brandt

parent
d7346cbfaf
commit
81bcd116a8
@ -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)
|
||||
|
@ -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']),
|
||||
]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user