asset_url
Returns the content delivery network (CDN) URL for a static asset of the theme. The filter supports both absolute and relative path resolution modes.
filepath | asset_url() returns a string.
Required params
filepath string: The file path. The following path types are supported:
-
Absolute path: References files under the theme's
publicdirectory. The passed value must exclude thepublicdirectory. For example, if you want to reference the/public/a.jsfile, passa.js. -
Relative path: Resolves the asset path based on the location of the file where the expression resides. The passed value must start with a period, such as
./a.jsor../one/test.js.
Examples
Absolute path
When the resource to be referenced is at /public/a.js, pass a.js to resolve the CDN URL.
{{ "a.js" | asset_url() }}
Relative path
If the file containing the expression is located at sections/test/two/two.html, and the resource to be referenced is at sections/test/one/test.js, pass ../one/test.js to resolve the CDN URL.
{{ "../one/test.js" | asset_url() }}