Skip to content

Unable to use use statements in a blade template that is included #15

Open
@owenvoke

Description

@owenvoke

I thought I'd just add an issue so that this doesn't get lost, however I'm currently looking into it a bit. 👍🏻

See owenvoke#3 for a fixture that demonstrates this issue.

When using the @include() directive with a file that contains use statements, in standard Blade it compiles to separate files, whereas (AFAICT) this package compiles to a single file which is checked (correct me if I'm wrong). But this causes the use statements to fail as they are in the global scope. Resulting in a PHP syntax error.

The error that will be output is:

PhpParser\Error: Syntax error, unexpected T_USE on line 5

Looks like it's because the use statement is embedded inside a function block when it's compiled. 🤔 e.g.

<?php
(function ()  {
    use Illuminate\Support\Facades\URL;

    URL::current();
});

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions