In a recent application where we use Twig, we assign httpBasePath as follows:
$view = $app->view()->getEnvironment(); $view->addGlobal('httpBasePath', $app->request->getScriptName());
The addGlobal()
method is probably equivalent to $app->view()->appendData()
, I'm not sure.
The advantage of using $app->request->getScriptName()
is that we donβt need to manually set the folder name or care what it is: one developer can have a repo located at http://example.localhost
, and the other may be http://localhost/projects/slim
and no configuration is required.
source share