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

Blades extending layout #15

Open
EggIt opened this issue Aug 4, 2019 · 1 comment
Open

Blades extending layout #15

EggIt opened this issue Aug 4, 2019 · 1 comment

Comments

@EggIt
Copy link

EggIt commented Aug 4, 2019

Hi,

I got a blade file as follows:

@desktop
    @extends('layouts.app')

    @section('content')
        <h1>DESKTOP VERSION</h1>
    @endsection
@enddesktop

@handheld
    <h1>MOBILE VERSION</h1>
@endhandheld

The h1 tags are working as expected, on desktop it shows DESKTOP VERSION and on mobile it shows MOBILE VERSION.

But the same layout layouts.app is being used by both clients.

I expected the layout to be used by desktop only, is this an issue or did i miss something?

@barnabaskecskes
Copy link
Contributor

Hey @EggIt thanks for the issue. I think this happens because how @extends() work within the framework. I tried above and got the same results.

I don't know what your use-case is, but what I would probably do is to create separate layout files (eg. layouts.desktop and layouts.handheld). You can then use

View::share('layout', app('mobile-detect')->isMobile() ? 'layouts.handheld' : 'layouts.desktop');

in your AppServiceProvider::boot() for example, then you can just do @extends($layout) in your blade files and it would just pick the right one every time.

Note that app('mobile-detect') will expose the underlying third party implementation and the language is a bit different. To learn more, check the directive implementations and see how the one you need is composed.

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

2 participants