diff --git a/webapp/src/Twig/TwigExtension.php b/webapp/src/Twig/TwigExtension.php
index f233757237..9c5a42834d 100644
--- a/webapp/src/Twig/TwigExtension.php
+++ b/webapp/src/Twig/TwigExtension.php
@@ -31,6 +31,8 @@
use Symfony\Component\Intl\Countries;
use Symfony\Component\Intl\Exception\MissingResourceException;
use Symfony\Component\PropertyAccess\PropertyAccess;
+use Symfony\Component\Routing\Generator\UrlGenerator;
+use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
@@ -126,6 +128,7 @@ public function getFilters(): array
new TwigFilter('medalType', $this->awards->medalType(...)),
new TwigFilter('numTableActions', $this->numTableActions(...)),
new TwigFilter('extensionToMime', $this->extensionToMime(...)),
+ new TwigFilter('relativePath', $this->relativePath(...), ['is_safe' => ['html']]),
];
}
@@ -363,7 +366,7 @@ public static function statusIcon(string $status): string
$status);
}
- public function countryFlag(?string $alpha3CountryCode, bool $showFullname = false): string
+ public function countryFlag(?string $alpha3CountryCode, bool $showFullname = false, bool $relative = false): string
{
if (empty($alpha3CountryCode)) {
return '';
@@ -376,6 +379,7 @@ public function countryFlag(?string $alpha3CountryCode, bool $showFullname = fal
}
$assetFunction = $this->twig->getFunction('asset')->getCallable();
$countryFlagUrl = call_user_func($assetFunction, sprintf('flags/4x3/%s.svg', $countryAlpha2));
+ $countryFlagUrl = $this->relativePath($countryFlagUrl, $relative);
$countryName = Countries::getAlpha3Name($alpha3CountryCode);
@@ -387,11 +391,12 @@ public function countryFlag(?string $alpha3CountryCode, bool $showFullname = fal
$countryFlagUrl, $alpha3CountryCode, $countryName);
}
- public function affiliationLogo(string $affiliationId, string $shortName): string
+ public function affiliationLogo(string $affiliationId, string $shortName, bool $relative = false): string
{
if ($asset = $this->dj->assetPath($affiliationId, 'affiliation')) {
$assetFunction = $this->twig->getFunction('asset')->getCallable();
$assetUrl = call_user_func($assetFunction, $asset);
+ $assetUrl = $this->relativePath($assetUrl, $relative);
return sprintf('',
htmlspecialchars($assetUrl), htmlspecialchars($shortName));
}
@@ -1195,7 +1200,7 @@ public function problemBadgeMaybe(
}
$submissionsUrl = $static
- ? $this->router->generate('public_submissions_data')
+ ? $this->router->generate('public_submissions_data', referenceType: UrlGeneratorInterface::RELATIVE_PATH)
: $this->router->generate('public_submissions_data_cell', [
'teamId' => $score->team->getExternalid(),
'problemId' => $problem->getExternalId(),
@@ -1381,4 +1386,14 @@ public function extensionToMime(string $extension): string
{
return DOMJudgeService::EXTENSION_TO_MIMETYPE[$extension];
}
+
+ public function relativePath(string $path, bool $relative = true) : string
+ {
+ if (!$relative) {
+ return $path;
+ }
+ return UrlGenerator::getRelativePath(
+ $this->router->getContext()->getBaseUrl()
+ . $this->router->getContext()->getPathInfo(), $path);
+ }
}
diff --git a/webapp/templates/base.html.twig b/webapp/templates/base.html.twig
index e953356b67..4cf737cdba 100644
--- a/webapp/templates/base.html.twig
+++ b/webapp/templates/base.html.twig
@@ -1,33 +1,35 @@
+{% if static is not defined %}
+ {% set static = false %}
+{% endif %}