Skip to content

view helper asseturl

David Spreekmeester edited this page Dec 2, 2014 · 1 revision

View helper AssetUrl

The assetUrl helper is used to render a URL to the configured CDN:

<?php
echo $this->assetUrl('/css/base.css');
?>

Its output is dependent on whatever's configured in the project's cdn settings. Is it a local CDN, then the output will likely be /css/base.css. Is it an S3 CDN? Then the output will probably be something like http://static.myproject.com/css/base.css.

Versioned build paths

Recently we've begun building separate production and development versions of CSS and Javascript. On top of that we now render this stuff in versioned paths that reflect the current semver.

AssetUrl has been updated to work with this. Make sure you configure assets.<extension>.root in the configuration, like so:

assets.css.root = "/css/build/dev"
assets.js.root = "/js/build/dev"

Then, pass only the basename of the file to assetUrl. It will then render something along the lines of /css/build/dev/v1.0.9/base.css.

Note that it's extremely important to always build assets when deploying a project! Since every time semver is updated the path to the assets changes the developer deploying is responsible for generating new assets.

Clone this wiki locally