You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-7Lines changed: 34 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -112,16 +112,43 @@ return [
112
112
* Create the widget and add the static function. For example:
113
113
114
114
```php
115
-
public static function insertList() {
116
-
return self::widget([
117
-
//your params
118
-
]);
115
+
namespace app\widgets;
116
+
117
+
use yii\base\Widget;
118
+
119
+
/**
120
+
* Class MyWidget
121
+
* @package app\widgets
122
+
*/
123
+
class MyWidget extends Widget
124
+
{
125
+
/**
126
+
* @inheritdoc
127
+
*/
128
+
public function run()
129
+
{
130
+
parent::run();
131
+
132
+
echo 'Text from widget';
133
+
}
134
+
135
+
/**
136
+
* This function used for render the widget in the cms pages
137
+
*
138
+
* @return string
139
+
*/
140
+
public static function show()
141
+
{
142
+
return self::widget([
143
+
// additional params
144
+
]);
145
+
}
119
146
}
120
147
```
121
-
* When you create the page via admin panel add the following code to the content:
148
+
* When you create the page via admin panel add the following code to the page content:
122
149
123
150
```
124
-
\app\widgets\MyWidget:list() // call the function insertList placed in MyWidget class
151
+
[[\app\widgets\MyWidget:show]]
125
152
```
126
153
2. You can use parameters in your page content, for example: {siteName}, {homeUrl}. For parsing this parameters you can use the `baseTemplateParams` property:
0 commit comments