All other helpers
Following is the list of all other available view helpers.
app
Reference to the Application instance.
@if(app.nodeEnvironment === 'development')
Print some debug log
@endif
env
Reference to the Env.get method.
{{ env('APP_URL') }}
config
Reference to the Config.get method.
{{ config('app.appKey') }}
asset
The asset
helper returns the path to a compiled frontend assets
by doing a lookup inside the manifest.json
file.
<script src="{{ asset('assets/app.js') }}"></script>
<link
rel="stylesheet"
type="text/css"
href="{{ asset('assets/app.css') }}"
>
assetsManager
The assetsManager
helpers is a reference to the instance of AssetsManager class
.
You will hardly rely on assets manager directly, as the asset
helper and the @entryPointStyles
and @entryPointScripts
tags let you reference the assets inside your templates.
csrfToken
Returns the value of the CSRF token. The helper is only available when the @adonisjs/shield
is installed and configured.
<input type="hidden" value="{{ csrfToken }}" name="_csrf">
csrfMeta
Returns a meta tag with the csrf token as the content. The helper is only available when the @adonisjs/shield
is installed and configured.
<head>
{{ csrfMeta() }}
</head>
csrfField
Returns the hidden input element for the CSRF token. The helper is only available when the @adonisjs/shield
is installed and configured.
<form method="POST" action="posts">
{{ csrfField() }}
</form>
cspNonce
Returns the value for the nonce
to be used with inline script tags. Make sure to read the CSP section
in the web security guide. The helper is only available when the @adonisjs/shield
is installed and configured.
<script nonce="{{ cspNonce }}">
</script>
request
Reference to the ctx.request instance. You can use it to access to the current url.
<a href="{{ route('UsersController.index') }}" class="{{ (request.matchesRoute('namedRoute')) ? 'link-active' : 'link-inactive' }}">
Users
</a>
auth
Reference to the ctx.auth instance. You can use it to display the specific portion of your markup conditionally.
This helper is only available when using the @adonisjs/auth
package.
@if(auth.isLoggedIn)
<p> Hello {{ auth.user.username }} </p>
@endif
bouncer
Reference to the ctx.bouncer instance. You can make use of the @can/@cannot tags to conditionally display markup inside your templates.
This helper is only available when using the @adonisjs/bouncer
package.
@if(await bouncer.allows('editPost'))
<a href="/posts/1/edit"> Edit post </a>
@end
i18n
An instance of i18n
for the default locale is shared with the templates as a global property.
However, the DetectUserLocale middleware overrides this property and shares a request specific instance for the current user's locale.
{{ i18n.locale }}
{{ i18n.formatNumber(100) }}
t
The t
helper is an alias for the i18n.formatMessage
method.
{{ t('messages.title') }}
getDefaultLocale
Returns the default locale for the application.
{{ getDefaultLocale() }}
getSupportedLocales
Returns an array of the supported locales.
{{ getSupportedLocales() }}