Miguel Borges
Miguel Borges

Reputation: 7669

Laravel Theme for managing layouts

I'm starting to develop my master's thesis in laravel 4 and now needed a package for managing themes. The app would have, for example, 3 themes: admin, Theme1 and Theme2.

Do you suggest any?

some features that would be interesting to have the package:

Upvotes: 3

Views: 9107

Answers (4)

igaster
igaster

Reputation: 13663

If you have switched to Laravel 5 you can try my package with features like:

  • Views & Asset seperation in theme folders
  • Theme inheritence: Extend any theme and create Theme hierarcies

Try it here: igaster/laravel-theme

Upvotes: 2

windmaomao
windmaomao

Reputation: 7680

This is my DIY way of managing themes in laravel and I have applied this to couple of my projects in the past, however this is not an automatic way that the other answers offers.

I found front-end person very creative, so I try to keep them as isolated as possible so that they don't have to know too much of the backend stuff before they can make contributions. Therefore, I created a folder called themes under public.

public
    themes
        default
            assets
            views
                layouts
                mockups
                pages
                partials

what's inside the default theme folder is really arbitrary, as long as you can keep your theme files manageable.

Then I'll rely on the third party tool, ex. CodeKit etc. to do the css js compilation work. So this is not really Laravel specific topic any more.

To add another theme, just add another folder under themes folder. In order to get the above work, you still need to sort out the theme loader yourself, because we moved to a custom theme location. I'll put the following in the controller

/**
 * Register a theme path relative to public
 *
 * @param string $name Theme name
 * @param string $path Theme path
 * @param string $asset_name Asset name of the theme, {$asset_name}_path will be registered at the template
 * @param string $asset_path Asset path of the theme, {$asset_name}_path will point to $asset_path
 */
protected function registerPublicPath($name, $path, $asset_name = '', $asset_path = '') {
    if (empty($asset_name)) {
        $asset_name = $name;
    }
    if (empty($asset_path)) {
        $asset_path = $path;
    }

    $path = public_path() . $path;
    View::addLocation($path);
    View::addNamespace($name, $path);
    View::share($asset_name . '_path', url('/') . $asset_path);
}

and call the default theme before use

    // Define a theme namespace folder under public
    $this->registerPublicPath(
        'default', '/themes/default/views',
        'asset', '/themes/default/assets'
    );

the way I did above is called "creating a theme engine" or "create a base theme" (ex. in Drupal).

Upvotes: 2

Tee Plus
Tee Plus

Reputation: 758

I wrote a package name "Theme".

https://github.com/teepluss/laravel4-theme

Upvotes: 3

Jason Lewis
Jason Lewis

Reputation: 18665

Sounds like you need to get your hands on the Cartalyst Themes package. Ticks all your boxes as far as I can tell.

If you're not keen on paying for a subscription then you might need to look at rolling your own. There's a number of asset management packages out there (Assetic, Basset, and Jeffrey Way's Laravel Guard) to help you get started on that front. As for the actual swapping out themes portion you'll need to implement something yourself there.

Upvotes: 4

Related Questions