Skip to content

Instantly share code, notes, and snippets.

@Insolita
Last active May 31, 2017 18:33
Show Gist options
  • Save Insolita/21917cba8a20d008db64182566bc02d4 to your computer and use it in GitHub Desktop.
Save Insolita/21917cba8a20d008db64182566bc02d4 to your computer and use it in GitHub Desktop.
MyTwiggedView
'view'=>[
'class'=>\yii\web\View::class,
'defaultExtension' => 'twig',
'renderers' => [
'twig'=>[
'class'=>\yii\twig\ViewRenderer::class,
'cachePath' => '@app/runtime/Twig/cache',
'options' => [
'auto_reload' => true,
],
'functions' => [
'__t' => 'Yii::t',
new \Twig_SimpleFunction('jscode', function ($arg) {
return new \yii\web\JsExpression($arg);
}),
new \Twig_SimpleFunction('trunc', function ($arg, $len) {
return \yii\helpers\StringHelper::truncate($arg, $len, '...', null, true);
}),
new \Twig_SimpleFunction(
'frontUrl', function ($route) {
return Yii::$app->urlManagerFrontend->createAbsoluteUrl($route,true);
}
),
new \Twig_SimpleFunction(
'backUrl', function ($route) {
return Yii::$app->urlManagerBackend->createAbsoluteUrl($route,true);
}
),
],
'globals' => [
'html' => ['class' => \yii\helpers\Html::class],
],
'filters' => [
'jsonEncode' => '\yii\helpers\Json::encode',
'md5' => 'md5',
'asSize' => function ($arg) {
return Yii::$app->formatter->asShortSize($arg);
},
'asRelative' => function ($arg) {
return Yii::$app->formatter->asRelativeTime(strtotime($arg));
},
'asCurrency' => function ($arg) {
return Yii::$app->formatter->asCurrency($arg, 'RUR');
},
],
'uses' => [
'yii\bootstrap',
],
]
]
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment