Wordpress 是否可以在视图文件夹外使用laravel刀片?
我在公共子文件夹中找到了一个wordpress博客 我想在laravel视图中使用和使用blade相同的布局Wordpress 是否可以在视图文件夹外使用laravel刀片?,wordpress,laravel,laravel-blade,Wordpress,Laravel,Laravel Blade,我在公共子文件夹中找到了一个wordpress博客 我想在laravel视图中使用和使用blade相同的布局 还有其他方法可以实现吗?我通过以下功能实现了这一点: function bladeCompile ($from, $to, $data) { $fs = new \Illuminate\Filesystem\Filesystem; $b = new \Illuminate\View\Compilers\BladeCompiler($fs, __DIR__); $s
还有其他方法可以实现吗?我通过以下功能实现了这一点:
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);
}
您只需将路径添加到app/config/view.php,blade就会自动找到这些路径您可以定义自定义名称空间以便于使用:
// 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')
我要做的第一件事是在views文件夹中创建一个file.blade.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')