]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/front/controller/visitor/ShaarliVisitorController.php
Explicitly define base and asset path in templates
[github/shaarli/Shaarli.git] / application / front / controller / visitor / ShaarliVisitorController.php
index 98423d9000cfdca2958fcd685173974701074a49..b90b1e8f2f8396ef3eff59221b15db749a7be516 100644 (file)
@@ -60,6 +60,19 @@ abstract class ShaarliVisitorController
         $this->assignView('privateLinkcount', $this->container->bookmarkService->count(BookmarkFilter::$PRIVATE));
         $this->assignView('plugin_errors', $this->container->pluginManager->getErrors());
 
+        /*
+         * Define base path (if Shaarli is installed in a domain's subfolder, e.g. `/shaarli`)
+         * and the asset path (subfolder/tpl/default for default theme).
+         * These MUST be used to create an internal link or to include an asset in templates.
+         */
+        $this->assignView('base_path', $this->container->basePath);
+        $this->assignView(
+            'asset_path',
+            $this->container->basePath . '/' .
+            rtrim($this->container->conf->get('resource.raintpl_tpl', 'tpl'), '/') . '/' .
+            $this->container->conf->get('resource.theme', 'default')
+        );
+
         $this->executeDefaultHooks($template);
 
         return $this->container->pageBuilder->render($template);
@@ -105,7 +118,7 @@ abstract class ShaarliVisitorController
         array $clearParams = [],
         string $anchor = null
     ): Response {
-        $defaultPath = rtrim($request->getUri()->getBasePath(), '/') . '/';
+        $defaultPath = $this->container->basePath . '/';
         $referer = $this->container->environment['HTTP_REFERER'] ?? null;
 
         if (null !== $referer) {