Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy Option to add some variables to all views? #114

Open
benyanke opened this issue Jan 25, 2018 · 3 comments
Open

Easy Option to add some variables to all views? #114

benyanke opened this issue Jan 25, 2018 · 3 comments

Comments

@benyanke
Copy link

In addition to controller-method specific variables, is there an easy way to also specify some variables to use on all pages? This would be used, for example, to pass options from config files to JS frontend apps.

@Luddinus
Copy link

You could load the javascript variables in a ViewComposer code.

@AlexCatch
Copy link

Yeah like @Luddinus said, create a ViewServiceProvider & in the boot method you can write something like this.

View::composer('*', function ($view) {
    // JS facade used here
});

@generalProf
Copy link

TLDR
Make sure you assign the vars prepend to a rendering view that does not extend a main view, rather put a empty view at the bottom of your content area for the composer to be able to pass the data through.
(I could be wrong but i think this is a @extend blade problem by not having the content within the view be rendered but rather passed through a @section to the main view)

For anyone that is having a hard time getting the data through to the front end using a composer file. this is what helped me.

What I was doing wrong:
In my JavaScript config I set the attach view to a view that extends a main view, with a content section within it that get's passed to the main view.

What I did to fix it:
In the JavaScript I set a new view which gets rendered within the front end since i place this view within the main view (where html body tag structure is) and that worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants