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

JR *_*Tan 5 wordpress laravel laravel-blade

我在public子文件夹中有一个wordpress博客.

我想使用与使用刀片的laravel视图相同的布局.

反正有没有实现这一目标?

use*_*466 5

你需要将你的路径添加到app/config/view.php,刀片会自动找到它们


Mar*_*rco 5

您可以定义自定义命名空间以方便使用:

// 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')
Run Code Online (Sandbox Code Playgroud)


kar*_*elv 2

我设法通过以下功能来做到这一点:

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);
}
Run Code Online (Sandbox Code Playgroud)

然后使用:

$data = array ( // equivalent to the 'with' function.
    'parameter' => 'value';
    );
bladeCompile ('input.blade.file', 'result.file', $data);
Run Code Online (Sandbox Code Playgroud)