Skip to content

Instantly share code, notes, and snippets.

@A-312
Created June 24, 2019 07:47
Show Gist options
  • Save A-312/60db1d47cfe7c8163188c25d1cd80b7f to your computer and use it in GitHub Desktop.
Save A-312/60db1d47cfe7c8163188c25d1cd80b7f to your computer and use it in GitHub Desktop.
<?php
namespace Core\Bundle\Twig\TwigExtension;
use Core\Kernel\Kernel;
class assetExtension extends \Twig_Extension {
public function getFunctions() {
return array(
new \Twig_SimpleFunction("asset", array($this, "asset"))
);
}
public function asset($url) {
$kernel = Kernel::getCore();
$res = $kernel->getConfig()["res"];
$router = ($kernel->isDevEnvironment()) ? "/res_dev.php" : "";
return $res["scheme"]."://".$res["host"].$router.(($url[0]!="/")?"/":"").$url;
}
public function getName() {
return "assetExtension";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment