| Current Path : /var/www/html/crowdfunding/common/components/ |
| Current File : /var/www/html/crowdfunding/common/components/PortalModuleViewRenderer.php |
<?php
namespace common\components;
use common\components\PortalTagContents;
class PortalModuleViewRenderer extends \yii\twig\ViewRenderer {
const PATH_ALIAS = '@frontend/runtime/frontendpage';
public function render($view, $content, $params)
{
if(empty($view)) {
$view = 'index';
$loader = new \Twig\Loader\ArrayLoader([
'index' => $content
]);
} else {
$loader = new \Twig\Loader\FilesystemLoader(\Yii::getAlias(self::PATH_ALIAS));
}
$this->call($this->twig);
$this->twig->setLoader($loader);
$this->addExtensions([\yii\twig\html\HtmlHelperExtension::class]);
$this->addExtensions([\Twig\Extension\DebugExtension::class]);
// Change lexer syntax (must be set after other settings)
if (!empty($this->lexerOptions)) {
$this->setLexerOptions($this->lexerOptions);
}
return $this->twig->render($view, $params);
}
private function call(\Twig\Environment $twig) {
// addon filter
$twig->addFilter(
new \Twig\TwigFilter('ksort', function ($context, array $options = []) {
ksort($context);
return $context;
}, [
'is_variadic' => true
])
);
// content
$twig->addFunction(
new \Twig\TwigFunction('content', function ($context, $options = []) {
extract($options);
try {
$path = PortalTagContents::contentIsExist($context);
if(!empty($path)) {
include($path);
}
} catch (\Throwable $t) {
throw new \Exception('Error on tags "'. $context .'" with message :- ' . $t->getMessage());
}
})
);
}
}