Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 是否可以在视图文件夹外使用laravel刀片?_Wordpress_Laravel_Laravel Blade - Fatal编程技术网

Wordpress 是否可以在视图文件夹外使用laravel刀片?

Wordpress 是否可以在视图文件夹外使用laravel刀片?,wordpress,laravel,laravel-blade,Wordpress,Laravel,Laravel Blade,我在公共子文件夹中找到了一个wordpress博客 我想在laravel视图中使用和使用blade相同的布局 还有其他方法可以实现吗?我通过以下功能实现了这一点: function bladeCompile ($from, $to, $data) { $fs = new \Illuminate\Filesystem\Filesystem; $b = new \Illuminate\View\Compilers\BladeCompiler($fs, __DIR__); $s

我在公共子文件夹中找到了一个wordpress博客

我想在laravel视图中使用和使用blade相同的布局


还有其他方法可以实现吗?

我通过以下功能实现了这一点:

function bladeCompile ($from, $to, $data)
{
    $fs = new \Illuminate\Filesystem\Filesystem;
    $b = new \Illuminate\View\Compilers\BladeCompiler($fs, __DIR__);
    $src = $b->compileString (file_get_contents($from));

    $isPhp = false;
    if (substr( $src, 0, 5 ) === "<?php")
    {
        $isPhp = true;
        $src = substr($src, 5);
    }
    $tempFileName = tempnam("/tmp", "blade-compile");
    file_put_contents($tempFileName, $src);

    ob_start();

    extract($data);

    include $tempFileName;
    $out = ob_get_clean();
    if ($isPhp)
    {
        $out = '<?php'.$out;
    }
    file_put_contents($to, $out);
}

您只需将路径添加到app/config/view.php,blade就会自动找到这些路径

您可以定义自定义名称空间以便于使用:

// Register your custom namespace in your AppServiceProvider in the boot() method
view()->addNamespace('custom_views', app_path('custom_path'));

// usage:
view('custom_views::some.view.name')

我要做的第一件事是在views文件夹中创建一个file.blade.php,然后在该文件中包含()来自外部的文件。
// Register your custom namespace in your AppServiceProvider in the boot() method
view()->addNamespace('custom_views', app_path('custom_path'));

// usage:
view('custom_views::some.view.name')