是否可以在视图文件夹外部使用laravel刀片? [英] Is that possible to use laravel blade outside the view folder?
本文介绍了是否可以在视图文件夹外部使用laravel刀片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在公共子文件夹中有一个wordpress博客.
I got a wordpress blog inside the public sub folder.
我想在laravel视图中使用与使用Blade相同的布局.
I wanted to use same layout with the laravel view that using blade.
反正有实现这一目标的方法吗?
Is there anyway to achieve that?
推荐答案
我设法通过以下功能做到了这一点:
I managed to do this with the following function:
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);
这篇关于是否可以在视图文件夹外部使用laravel刀片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文