Print variable .env in edge template

Hi,

How do I print a variable (.env) inside the edge template?

Create a view global to access the value. NOTE: Do not dump entire .env file inside your views, since it may contain sensitive values.

Put the following code inside start/hooks.js file under after.providersBooted hook.

const { hooks } = require('@adonisjs/ignitor')

hooks.after.providersBooted(() => {
  const Env = use('Env')
  const View = use('View')

  View.global('name_you_like', function () {
    return Env.get('VARIABLE')
  })
})

and then use it as

{{ name_you_like() }} 
1 Like

Thanks @virk