You can generate the url from the request object:
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
You could make a twig extension that cuts the /web
part of your path and uses the request to generate the base url.
see SymfonyComponentRoutingGeneratorUrlGenerator::doGenerate
for a more solid implementation.
Also, Twig has access to the request from app.request
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…