반응형
뷰 폴더 밖에서 라라벨 블레이드를 사용할 수 있습니까?
공용 서브폴더 안에 워드프레스 블로그가 있어요
저는 블레이드를 사용한 라라벨 뷰와 같은 레이아웃을 사용하고 싶었습니다.
그것을 달성할 수 있는 방법이 있습니까?
앱/구성/뷰에 경로만 추가하면 됩니다.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
반응형
'sourcetip' 카테고리의 다른 글
TypeScript에서 JSON 파일 가져오기 (0) | 2023.04.03 |
---|---|
React-js는 라벨의 'for' 속성을 무시합니다. (0) | 2023.04.03 |
wordpress 플러그인의 다른 페이지로 양식을 제출하는 방법 (0) | 2023.04.03 |
반응 헬메트의 목적은 무엇입니까? (0) | 2023.04.03 |
상태 변경 시 반응 구성 요소가 다시 렌더링되지 않음 (0) | 2023.04.03 |