Reputation: 33
You know wordpress template system. I'm writing a simple script with Laravel. I'm very beginner at Laravel. I need to more than one template and it must be selectable at admin panel.
I created subfolders at views doc like that:
project/resources/views
I keep template's doc name in the database when one is selected. I want to run the site selected template.
How to I can do it?
Upvotes: 0
Views: 1143
Reputation: 694
Firstly, Wordpress has a million lines of code and it's open source. You have to observe their codes from github repo if you have ever never implemented an templating engine as same as Wordpress or any kind of equivalent applications. It's not best practice however you can simply create a new namespace for the view from the app container.
You can boot your namespace definition on AppServiceProvider
app("view")->addNamespace("theme",base_path('themes/'.DEFAULT_TEMPLATE_FOLDER_NAME));
Within this way, you can pass different folders as a view. you have to call your view files via themes::
namespace.
Let's assume you have a default folder in the themes folder as a default template and there is index.blade.php
inside of it. You have to call it as a return view('themes::index')
in the controller. If DEFAULT_TEMPLATE_FOLDER_NAME changed, the themes::
namespace will point to changed destination due to App Service Provider. It's a simplest version of wordpress-like templating. For the best case, you have to observe different kind of open source projects.
Upvotes: 1