How to implement theming in Laravel 5 - laravel-5

I want to create a theme for laravel 5, but not getting any appropriate tutorial for it.
Does anyone knows how to achieve it in laravel 5.

There is a package for managing multiple themes in Laravel 5.
Found here: https://github.com/igaster/laravel-theme
If you want to do it yourself, you can easily achieve it with following steps:
Create a config for your different themes in:
// app/config/site.php
return [
'theme' => 'default'
];
create a new folder for your views. One folder for each theme:
themes/default/views
themes/other_theme/views
And put your blade views file in each directory matching your different themes.
Register which theme the site should use by default:
$theme = Config::get('site.theme');
View::addLocation(base_path() . '/themes/' . $theme . '/views/');
Additionally you can configure different assets folders for the different themes to compile js and css files with gulp, and so on.

there is a very good package to use in
https://github.com/FaCuZ/laravel-theme

Related

Laravel Different Views Folder

I have downloaded a project and I noticed that the project use views from different directory not the usual directory which are
\resources\views
but instead it create a new folder name themes and insert all the views in there.
\themes\app\views
Views Directory
and also I noticed in the controller they return view by using getAppTheme()
Return View using getAppTheme()
Anyone know how I can create a new folder outside the \resources\views folder for all my views file. And how I can return view using getAppTheme() just like in the picture.
there a config for view path at laravel located at config/views.php
you can configure there by change this
'paths' => [
resource_path('views'), //this value you need to change
],
Thanks but the answer I was looking for is in here
https://github.com/Shipu/themevel
Anyway, thanks again

Angular 2 base_href linking assets issue

I am using laravel 5.3 with angular 2 for my project and using webpack for compilation of the assets including js and css.
I am trying to use same font awesome and bootstrap for the client and admin area.
I have the folder structure of laravel with everything inside js directory.
|-public
|-js
|-assets
|-fontawesome-webfonts.woff
|-image1.png
|-vendor.bundle.js
|-polyfill.bundle.js
For Angular 2 routes we need to add the base href to the main template which i have also added.
<base href="/">
Admin url is localhost:8000/admin
and user url is localhost:8000
I have included the bundles like
{!! Html::script('js/vendor.bundle.js') !!}
and the vendor have imported the less files as:
vendor.bundle.js
import 'admin-lte/build/less/AdminLTE.less';
import 'font-awesome/less/font-awesome.less';
The main issue is that when i use the same vendor.bundle.js to both user and admin pages the user page works fine since it loads the fonts from js/assets/fontawesome-webfonts.woff but when i load the admin page it couldn't load the fonts as it searches from admin/js/assets/fontawesome-webfonts.woff which is not the correct directory.
How could i make Angular search into js/assets/fontawesome-webfonts.woff for both url?
The issue is displayed in the image too.
I just figured it out by myself using the url-loader webpack plugin.
You should leave the base href to as it is and configure the assets.
I just needed to add a new test only for the fonts
{
test: /\.(svg|woff|woff2|ttf|eot)$/,
loader: 'url-loader?limit=10000&name=assets/[hash].[ext]&publicPath=/js/'
}
You need to specify the publicPath and add the other directories to name.
That's all. Hope it will save someone's precious time.
Note: don't forget the '/' at the front of the public path

Laravel 4 - Accessing Folders

I am new to Laravel 4, and I come from a Zend Framework background. I'd like to create a folder app/forms and keep all my forms there. How can I refer to the form in the controller and within the view.blade files?
By default, the root of the view files folder is app/views so if you create a folder in views like app/views/forms then you may refer the form by it's name from a controller like:
$form = View::make('forms.formfile');
Here, formfile is the name of the file that contains the form and it could be formfile.blade.php and to refer/include the form file from a view you may use #include:
// In a blade view file
#include('forms.form1')
Assume that, form1 is a blade view inside the forms folder and saved as form1.blade.php, you may also use sub-folders inside the forms folder, for example in views/forms/user folder you may keep a view named index.blade.php and use it like:
// From a controller
$userForm = View::make('forms/user/index');
From a view file: (folders are separated by .)
#include('forms.user.index') // file: app/views/forms/user/index.blade.php
You can also nest views in the controller, check the manual for more.
From the standpoint of Laravel, HTML forms (and all presentation related things ) belongs to app/views/ folder. Exceptions are package specific views. For example some commands has their own stubs and views and they are usually stored inside package.
Laravel is very flexibile, and you can move things around and create new folders and namespaces. You just have to tell composer that you are changing Laravel default structure, and dumpautoload. That is if you only want to create new folder with internal reference. If you want something with more scope and visibility you'll have to bind that to container, so that will be visible inside whole application.
You are coming from the Zend world, so I can understand that you want to move some of Zend "flavour" to Laravel. Although is it possible, I would really recommend you to take some time and learn how Laravel works. There are some great ideas and design inside. Of course, Zend has its own quality, but hey - this is Laravel :)

Load css/js files in Laravel 4 with Composer?

I'm working on creating a new project in Laravel 4. I have a tiny bit of experience in Laravel 3, in which I got used to the assets system. I'm now having a lot of trouble figuring out how to load CSS and JS files in the new system.
I believe I should be using Composer PHP, but I'm not sure how. Where do I put the actual .css and .js files? And then how do I load them with Composer to be utilized in the Laravel project?
I know there are outside plugins like Best Asset, etc. that are written to replicate the Assets system of Laravel 3, but I was hoping to understand the new system and not have to use an outside plugin.
Any help? Thanks.
You don't need Composer for your css/js assets. You can use assets pretty much the same as with Laravel 3
You can just place them in your public folder and reference them in your views. You can use plain html, or use the HtmlBuilder: HTML::style('style.css') and HTML::script('script.js')
You must take care of case sensitive.
This class must write with uppercase.
HTML::style('style.css');
HTML::script('script.js');
Laravel stylesheets and javascript don't load for non-base routes

Codeigniter 2.1.3 HMVC templates from /public/themes

I'm using codeigniter 2.1.3 with wiredesignz HMVC, I was wondering how would I get templates from the public folder rather than the modules/module/views?
example structure
application/projects/projectname/ciappstructure
application/system/etc/
public/themes/themename/layout
public/themes/themename/pages
public/themes/themename/widgets
public/themes/themename/etc
I would love to use html files and have my template library sort out the tags and placement of widgets or modules, all modules and theme data being pulled from the DB
like:
$homepage = $this->load->view(FCPATH.'themes/$theme/pages/homepage.html', $data, TRUE);
Oh and another quick question, I'm new to HMVC, could I call modules::run('module/method', $params, $...); from a template library (/application/projects/project/libraries/template.php) ?
I've tried a few things but I can't seem to get anything working, any ideas are much appreciated! Thanks in advance
First, the $this->load->view() load views with .php extension not .html files, Second, this method only load the views on views/ folder.
Therefore, your need config first your modules folder in application/config.php file. Place this on the ends of file.
$config['modules_locations'] = array(
APPPATH . 'modules/' => '../modules/'
);
Next, create your first module with views as sub-folder, and create your view file with .php as extension.
- modules/
--- my_module/
------ views/
--------- my_view.php
Next, in your controller, load the view with the ubication of your module.
$this->load->view('my_module/my_view');
This must run, you can try and read more about the documentation.
Hope this help you!

Resources