diff --git a/core/frontend/helpers/asset.js b/core/frontend/helpers/asset.js index 36a7d93d0e..a33eaa5224 100644 --- a/core/frontend/helpers/asset.js +++ b/core/frontend/helpers/asset.js @@ -2,14 +2,19 @@ // Usage: `{{asset "css/screen.css"}}` // // Returns the path to the specified asset. -const proxy = require('./proxy'); +const {SafeString, metaData, errors, i18n} = require('./proxy'); const get = require('lodash/get'); -const {SafeString} = proxy; -const {getAssetUrl} = proxy.metaData; +const {getAssetUrl} = metaData; module.exports = function asset(path, options) { const hasMinFile = get(options, 'hash.hasMinFile'); + if (!path) { + throw new errors.IncorrectUsageError({ + message: i18n.t('warnings.helpers.asset.pathIsRequired') + }); + } + return new SafeString( getAssetUrl(path, hasMinFile) ); diff --git a/core/server/translations/en.json b/core/server/translations/en.json index c2a86b7d7a..80e176d8bf 100644 --- a/core/server/translations/en.json +++ b/core/server/translations/en.json @@ -578,6 +578,9 @@ "flagMustBeEnabled": "The {flagName} flag must be enabled in labs if you wish to use the \\{\\{{helperName}\\}\\} helper.", "seeLink": "See {url}", "mustBeCalledAsBlock": "The \\{\\{{helperName}\\}\\} helper must be called as a block. E.g. \\{\\{#{helperName}\\}\\} \\{\\{/{helperName}\\}\\}", + "asset": { + "pathIsRequired": "The \\{\\{asset\\}\\} helper must be passed a path" + }, "foreach": { "iteratorNeeded": "Need to pass an iterator to #foreach" },