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

Issues with compiling layouts or page #12

Open
thewebartisan7 opened this issue Jan 21, 2020 · 2 comments
Open

Issues with compiling layouts or page #12

thewebartisan7 opened this issue Jan 21, 2020 · 2 comments

Comments

@thewebartisan7
Copy link

I have tested this package for compile my layout file which include too much things.

However the result was not as expected.

But commenting method implodeLayout() worked fine, this:

    private function compile($viewPath)
    {
        $blade = file_get_contents($viewPath);
        //$this->implodeLayout($blade);//A1 @inprogress
        $this->implodeIncludes($blade);//A2 @pending

        return $blade;
    }

Without this the main yield('content') is replaced by:

{{--yield didnt have alternative--}}

Is not designed for works also with layouts?

If I try to compile a view that extends a layout, also not works, this is the result (most part are removed):

{{-- Extend layout was here --}}

@section('content')
    <div>
This is content
    </div>
@endsection
 <!DOCTYPE html>
<html>
<head>
    <?php extract([]); ?>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{csrf_token()}}">
<title>{{config('app.name')}}@yield('head-title')</title>
@stack('styles')
</head>
<body>
    <main class="app">
       {{--yield didnt have alternative--}}  // ... HERE SHOULD BE yield content
    </main>
@section('scripts')
    <?php extract([]); ?>
@stack('scripts')
<?php extract([]); ?>

// ... removed to shorten issue

@show
</body>
</html>

As you can see yield('content') is removed and the view compiled is on top and not inside content.

Maybe this works only with partials views?

Then I wonder why is added this php code for each included file:

<?php extract([]); ?>

Thanks

@thewebartisan7
Copy link
Author

I check a bit inside code and I understand now why not works compiling page that extend layout.

this code:

 $blade = preg_replace("/@section(?s).*?stop/si", "{{-- section was here --}}", $blade);

Doesn't work when @section is closed using @endsection, but must be @stop

Now remain only issue with compiling layouts.

Let me know if there is a way, I will continue to check in code maybe I understand.

Thanks

@thewebartisan7
Copy link
Author

thewebartisan7 commented Jan 21, 2020

I find a workaround for compile also layouts by keeping yields(). It was easy, but not sure if this can make some issue. I tested and seem works fine. But maybe I am introducing some issue. Please let me know what do you think.

    private function implodeLayout(&$blade)
    {
        $sections = $this->seperateSections($blade);//B1 @done
        $this->replaceLayout($blade);//B2 @done
        
        // Just commented this:
        //$this->replaceSections($blade, $sections);//B3 @inprogress
    }

If this works, could be add a new options for keep yield so that works also in this case.

What do you think?

I also see what it's used the extract() method, to extract variable passed to partials view.

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

1 participant