/** * Generates a real-link to the given path. * * @param array $context Template context. * @param string $path Path to file to generate link to. * * @return string */ public function link($context, $path) { if (!isset($context['_genry_page']) || !$context['_genry_page'] instanceof Page) { throw new \RuntimeException('Twig link() function requires "_genry_page" variable in the template to be set to the current ' . 'rendered page. It must have been overwritten in the context.'); } return $this->router->generateLink($path, $context['_genry_page']); }
/** * Makes an asset's URL relative to the given page. * * @param Asset $asset Asset to be made relative. * @param Page $relativeTo The "owning" page. */ protected function makeRelativeUrl(Asset $asset, Page $relativeTo) { $url = $asset->getUrl(); // omit external url's if (stripos($url, 'http://') === 0 || stripos($url, 'https://') === 0 || stripos($url, '//') === 0) { return true; } $url = $this->router->generateLink($url, $relativeTo); $asset->setUrl($url); }
/** * Generates a link to a class. * * @param string $class Class name. * @param Page $relativeTo Page to which it is relative. * * @return string */ public function generateClassLink($class, Page $relativeTo) { $path = $this->outputDir . str_replace(NS, DS, $class) . '.html'; return $this->router->generateLink($path, $relativeTo); }