sourcetip

뷰 폴더 밖에서 라라벨 블레이드를 사용할 수 있습니까?

fileupload 2023. 4. 3. 21:41
반응형

뷰 폴더 밖에서 라라벨 블레이드를 사용할 수 있습니까?

공용 서브폴더 안에 워드프레스 블로그가 있어요

저는 블레이드를 사용한 라라벨 뷰와 같은 레이아웃을 사용하고 싶었습니다.

그것을 달성할 수 있는 방법이 있습니까?

앱/구성/뷰에 경로만 추가하면 됩니다.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')

다음 기능으로 이 작업을 수행할 수중에 있습니다.

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);
}

그 후, 다음과 같이 합니다.

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

언급URL : https://stackoverflow.com/questions/17079369/is-that-possible-to-use-laravel-blade-outside-the-view-folder

반응형