Access Config inside all views

Hi
I want to access to Config inside all my views so I can use following script inside a view:

Config.get('...');

I’ve read views topic and configuration topic and edge.js globals but the examples are static or simple.

I found this page which explains how to make lodash global so I copied the script but it’s not working

    const Config = use('Config');

    View.global('Config', function (method, args) {
        return Config[method](args);
    });

any help. thank you

1 Like

You have just shared one piece of the picture, where’s the code on how you are using it?

The following should work easily.

const Config = use('Config')

View.global('config', function (key) {
  return Config.get(key)
})

and use it as follows.

{{ config('app.appKey') }}
3 Likes

Thank you virk
I O U an apology for my pull request on github that makes you think that me or others may think AdonisJS is a clone of Laravel, Maybe at first place it was but now AdonisJS has found it’s own way and actually it’s even better in some aspects.
SO I do apologize.

And one more thing, may be my or other people questions may sound silly from your point of view but they can help you improve the documentation of the framework. This framework is awesome for those who don’t want to bother themselves gathering every single part of an application like security, authentication, caching, routing, sessions, validator, database and much much more to make it work. and I think that’s the spirit of a framework like AdonisJS. and this can attract newbies to you framework which need more detailed documentation and such questions can become useful for them. the point is AdonisJS documentation is good but can be better :blush:

I 100% agree that documentation can become better. Infact I am planning to have someone work fulltime on the documentation only.

So feel free to contribute to docs or any other part of the framework

Yeah, absolutely, I would gladly like to help :+1:t4:

Forgot const View = use('View') ?