/** * {@inheritdoc} */ public function register(View $view) { $view->on('head', function ($event) use($view) { $view->trigger('scripts', [$this->scripts]); $event->addResult($this->render()); }, 5); }
/** * {@inheritdoc} */ public function register(View $view) { $view->on('render', function ($event) { if ($this->has($name = $event->getTemplate())) { $event->setTemplate($this->get($name)); } }, 10); }
/** * product shown in frontend * @param Event $event * @param File $file * @param View $view */ public function onProductPrepare($event, $file, View $view) { static $products; if (!$products) { $products = []; } if (!empty($file->id) && $file->get('cart_active')) { if (!($product = Product::where(['item_id = ?', 'item_model = ?'], [$file->id, 'Bixie\\Download\\Model\\File'])->first())) { $product = Product::createNew(['item_id' => $file->id, 'item_model' => 'Bixie\\Download\\Model\\File']); } $file->product = $product; $products[$file->id] = $product; $view->script('bixie-cart'); $view->data('$cart', ['products' => $products, 'periods' => self::$periods]); } }
/** * {@inheritdoc} */ public function register(View $view) { $view->on('render', function ($event) { $name = $event->getTemplate(); if (isset($this->placeholder[$name])) { $this->deferred[$name] = clone $event; $event->setResult($this->placeholder[$name]); $event->stopPropagation(); } }, 15); $this->events->on('response', function ($e, $request, $response) use($view) { foreach ($this->deferred as $name => $event) { $view->trigger($event->setName($name), [$view]); $response->setContent(str_replace($this->placeholder[$name], $event->getResult(), $response->getContent())); } }, 10); }
use Pagekit\View\Helper\GravatarHelper; use Pagekit\View\Helper\MapHelper; use Pagekit\View\Helper\MarkdownHelper; use Pagekit\View\Helper\MetaHelper; use Pagekit\View\Helper\ScriptHelper; use Pagekit\View\Helper\SectionHelper; use Pagekit\View\Helper\StyleHelper; use Pagekit\View\Helper\TokenHelper; use Pagekit\View\Helper\UrlHelper; use Pagekit\View\Loader\FilesystemLoader; use Pagekit\View\PhpEngine; use Pagekit\View\View; use Symfony\Component\HttpFoundation\Response; return ['name' => 'view', 'main' => function ($app) { $app['view'] = function ($app) { $view = new View(new PrefixEventDispatcher('view.', $app['events'])); $view->addEngine(new PhpEngine(null, isset($app['locator']) ? new FilesystemLoader($app['locator']) : null)); $view->addGlobal('app', $app); $view->addGlobal('view', $view); $view->addHelpers([new DataHelper(), new DeferredHelper($app['events']), new GravatarHelper(), new MapHelper(), new MetaHelper(), new ScriptHelper($app['scripts']), new SectionHelper(), new StyleHelper($app['styles']), new UrlHelper($app['url'])]); if (isset($app['csrf'])) { $view->addHelper(new TokenHelper($app['csrf'])); } if (isset($app['markdown'])) { $view->addHelper(new MarkdownHelper($app['markdown'])); } return $view; }; $app['assets'] = function () { return new AssetFactory(); };
use Pagekit\View\Helper\MapHelper; use Pagekit\View\Helper\MarkdownHelper; use Pagekit\View\Helper\MetaHelper; use Pagekit\View\Helper\ScriptHelper; use Pagekit\View\Helper\SectionHelper; use Pagekit\View\Helper\StyleHelper; use Pagekit\View\Helper\TokenHelper; use Pagekit\View\Helper\UrlHelper; use Pagekit\View\Loader\FilesystemLoader; use Pagekit\View\PhpEngine; use Pagekit\View\View; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Templating\TemplateNameParser; return ['name' => 'view', 'include' => 'modules/*/index.php', 'require' => ['view/twig'], 'main' => function ($app) { $app['view'] = function ($app) { $view = new View(new PrefixEventDispatcher('view.', $app['events'])); $view->addEngine(new PhpEngine(null, isset($app['locator']) ? new FilesystemLoader($app['locator']) : null)); if (isset($app['twig'])) { $view->addEngine(new TwigEngine($app['twig'], new TemplateNameParser())); } $view->addGlobal('app', $app); $view->addGlobal('view', $view); $view->addHelpers([new DataHelper(), new DeferredHelper($app['events']), new GravatarHelper(), new MapHelper(), new MetaHelper(), new ScriptHelper($app['scripts']), new SectionHelper(), new StyleHelper($app['styles']), new UrlHelper($app['url'])]); if (isset($app['csrf'])) { $view->addHelper(new TokenHelper($app['csrf'])); } if (isset($app['markdown'])) { $view->addHelper(new MarkdownHelper($app['markdown'])); } return $view; };