Search code examples
phpviewlaravel-3sites

Multi-site framework in Laravel


I've just started working on a Content Management Framework using Laravel 3. It is not designed to be a database-driven app (that may come later). It is designed for web-designers wanting an easy and SEO-friendly way to make a static website.

In a nutshell, the designer would only need to create a default site, and any other [optional] sites (making it a multi-site framework, like Drupal) by means of working with a folder structure.

Currently, the structure has been designed as follows (not implemented yet, it is just an idea; it is also an alteration of Laravel's standard path structure):

public[_html]
root
    app // application folder
    bundles
    sites
        sites.json // used to determine the default site, and register any others
        {site-slug}
            info.json
            content // for page content that inherits a layout
                {page-slug}
                    info.json
                    content.blade.php
            layouts // site layouts: headers, footers, etc.
    stores // storage folder
    system // laravel folder

Here's my main issue right now: I have no idea how to extend the View class to look outside the standard views folder without having to use the path: prefix.

What is the best method of doing this?

Perhaps there is another templating engine that makes this task easier for me? Is there a suitable HAML engine for Laravel 3?

Note: I know there are content bundles that make use of Markdown, but that is not what I'm looking for.

Any help here would be hugely appreciated.


Solution

  • In the views.php Config file you should be able to add all the directories you want to include to an array

    EDIT

    Sorry this is for laravel 4. I would extend the view class and have it search an array of paths is the View::path method. You could set this array with the config files so you're call for the paths would be Config::get('views')

    MY SOLUTION

    A while ago I was working on a project and came up with a solution that avoids modifying any core files.

    in application/start.php

    Event::listen(View::loader, function($bundle, $view)
    {
        foreach (Config::get('views', array()) as $path) {
            if($file = View::file($bundle, $view, $path))
                return $file;
        }
    
        return View::file($bundle, $view, Bundle::path($bundle).'views');
    });
    

    in application/config/views.php (you'll have to create this)

    return array(
        path('app').'../myviews',
    );
    

    Now you can add any number of directories to this file and they will be checked before the default view directory is checked.