Skip to content

Instantly share code, notes, and snippets.

@cagataycali
Created September 14, 2015 12:30
Show Gist options
  • Save cagataycali/1e2aa3ef9fbb202c4a3a to your computer and use it in GitHub Desktop.
Save cagataycali/1e2aa3ef9fbb202c4a3a to your computer and use it in GitHub Desktop.

You can use the templating.helper.assets service. First define your assets base URL : # app/config/config.yml framework: templating: assets_base_url: "http://www.mywebsite.com/" Then just call the service from within your controller, command or wherever you are : <?php // src/Acme/Bundle/DemoBundle/Controller/DemoController.php namespace Acme\Bundle\DemoBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DemoController extends Controller { public function indexAction() { $myAssetUrl = $this ->get('templating.helper.assets') ->getUrl('bundles/acmedemo/js/main.js', $packageName = null) ; // $myAssetUrl is "http://www.mywebsite.com/bundles/acmedemo/js/main.js" return array(); } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment