JR *_*Tan 5 wordpress laravel laravel-blade
我在public子文件夹中有一个wordpress博客.
我想使用与使用刀片的laravel视图相同的布局.
反正有没有实现这一目标?
您可以定义自定义命名空间以方便使用:
// 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)
我设法通过以下功能来做到这一点:
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)
| 归档时间: |
|
| 查看次数: |
3774 次 |
| 最近记录: |