Skip to content

Commit

Permalink
Updated twig extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Leveille committed Jan 23, 2023
1 parent acd3796 commit 06ea054
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions modules/site/web/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use modules\site\helpers\StringHelper;

use Craft;
use craft\base\Element;
use craft\helpers\App;

Expand All @@ -25,11 +26,11 @@ public function getFunctions(): array
$url = null;
$site = $element->getSite();

if ($site->handle == 'en') {
if ($site->handle === 'en') {
$url = App::env('PREVIEW_EN_URL');
}

if ($site->handle == 'fr') {
if ($site->handle === 'fr') {
$url = App::env('PREVIEW_FR_URL');
}

Expand All @@ -43,6 +44,10 @@ public function getFunctions(): array
$url .= $element->uri;
}

if (Craft::$app->getConfig()->getGeneral()->addTrailingSlashesToUrls) {
$url = StringHelper::ensureRight($url, '/');
}

return $url.'?preview=true';
}),

Expand Down

0 comments on commit 06ea054

Please sign in to comment.