Helpers
Source code should be self explanatory, keep in mind that these functions are always available from anywhere (both php
and blade
files) in the global scope and that are loaded by the composer
autoloader mechanism.
We should not put too many functions here, just those related to systemic handling like construction of URLs, links and translations.
#
Global helpersThe following functions are always autoloaded and made available eveywhere in your app, both in php
files and in blade.php
template files.
formatUrl
#
With this function we can set a standard for trailing/untrailing slash and, eventually, make it optional. Now we enforce a trailing slash on all URLs.
@returns
string
, @params
name | type | required | default value | description |
---|---|---|---|---|
$url | string | false | '' | An absolute URL |
formatUrlPath
#
With this function we can set a standard for trailing/untrailing slash and, eventually, make it optional. Now we enforce a trailing slash on all URLs.
note
Don't pass here an absolute URL!
@returns
string
, @params
name | type | required | default value | description |
---|---|---|---|---|
$path | string | false | '' | A relative URL |
linkUrl
#
Construct a localised URL according to the standard URL formatting conventions.
@returns
string
, @params
name | type | required | default value | description |
---|---|---|---|---|
$slug | string | false | '' | A relative URL |
$locale | string | false | '' | A valid locale, e.g. en |
media
#
Output a an absolute URL to a remote media file. It uses as base URL the assets->media
value from the {CMS_API_URL}/structure
endpoint.
note
Don't pass here an absolute URL!
@returns
string
, @params
name | type | required | default value | description |
---|---|---|---|---|
$path | string | false | '' | A relative URL |
to
#
Dynamically generate a URL to the given route
.
@returns
string
, @params
name | type | required | default value | description |
---|---|---|---|---|
$route | string | false | '' | The unique route name |
$args | array | false | [] | The dynamic slug portions to interpolate |
to
)#
Examples (Given routes defined in {CMS_API_URL}/structure -> "routes"
as:
Here is how to create the links in your templates:
t
#
Dynamically translate a localised string optionally interpolating variables. Strings are defined in src/assets/translations.csv
, see I18n docs).
@returns
string
, @params
name | type | required | default value | description |
---|---|---|---|---|
$key | string | false | '' | The unique string name |
$args | array | false | null | The dynamic variables to interpolate |
See example usage in the translations
guide.
download
#
Dynamically generate a URL to a downladable file placed in src/assets/media
.
@returns
string
, @params
name | type | required | default value | description |
---|---|---|---|---|
$path | string | true | '' | The full path of the file relative to src/assets/media |
$viewIt | boolean | false | false | Wether you want to open the file instead of triggering an immediate download |
download
)#
Examples (Given a file example.pdf
placed in /src/assets/media/example.pdf
and a file example-nested.pdf
placed in /src/assets/media/some-folder/example-nested.pdf
here is how to create links in your templates:
downloadWithAuth
#
Dynamically generate a URL to a downladable file placed in src/assets/media
protecting the download with the auth
middleware.
This work exactly the same as the download
helper.