Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I load a custom blade view at run time

If I want to load a view from a custom folder at run time, I’m not sure how to do it.

I know I can add a permanent alternative to my view to the paths value in the config/view.php file. However I have tried adding to this at run time just before calling with no success

eg.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Config::set(['views.paths' => 'my/custom/path']);
return view('bladeinmycustompath'); 

this doesnt work. I have also tried using a full path to no avail.

Is there an easy way to render a specific blade file or add a custom path at run time.

I know I can simply add the path to the view.php file at design time but I dont want tot do this.

>Solution :

use Illuminate\Support\Facades\View;
public function loadCustomView()
{
    // Add the custom view path for this request
    View::addLocation('/path/to/your/custom/views');

    return view('customview'); // The view name without the .blade.php extension
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading