Autarky\Routing\UrlGenerator::getAssetUrl PHP Method

getAssetUrl() public method

Get the URL to an asset.
public getAssetUrl ( string $path, boolean $relative = false ) : string
$path string
$relative boolean
return string
    public function getAssetUrl($path, $relative = false)
    {
        if (substr($path, 0, 1) !== '/') {
            $path = '/' . $path;
        }
        if ($this->assetRoot !== null) {
            $base = $this->assetRoot;
        } else {
            if ($relative) {
                $base = $this->requests->getCurrentRequest()->getBaseUrl();
            } else {
                $base = $this->getRootUrl();
            }
        }
        return $base . $path;
    }

Usage Example

 /**
  * Implementation of the `asset(path)` twig function.
  *
  * @param  string  $path     Path to the asset, relative to the webroot or asset root.
  * @param  boolean $relative Whether to generate an absolute or relative URL.
  *
  * @return [type]            [description]
  */
 public function getAsset($path, $relative = false)
 {
     return $this->urlGenerator->getAssetUrl($path, $relative);
 }