So we have some websites. A lot of websites. About 394 from last count. They're all newspaper sites, they all want blogs, and we want them to be using Drupal for their blog platform. Unfortunately, they're all hosted on a content management system that isn't really meant to be a robust blogging platform. So we had a predicament on our hands. How do we clone 300+ websites into Drupal sites?
The creation and management of these sites on one Drupal installation is straightforward using Drupal's multi-site feature, along with a unified installation profile. So that wasn't our concern. However, of larger concern was the creation and management of 300+ Drupal themes using our existing websites as templates. Luckily, our CMS allows us to create one template that is available on every single site. This got us our base template from which we wanted our Drupal themes to be based off of.
So, I thought it would be excellent if we had a Drupal module that would:
A few brainstorming sessions and five hours of coding later, I've got a working Drupal module that does just that. Enter the Theme Generator module. For now, it serves our organization's very specific needs. However, I've got big plans for the module that may benefit others.
Here are some examples of our sites and their corresponding Drupal templates:
...and 391 others.
Here's how it works. Upload and enable the module, head over to '/admin/settings/theme_generator'. From this screen, you have 5 fields:
Template path
This should be a URL, either local or remote, to the HTML mockup you want to use as the source of your Drupal theme. For example:
http://www.mpnnow.com/drupal_owrap
Region replacement pattern
The generator will look for a pattern of text that it will use to build the Drupal regions. You can change that pattern here, but by default we use:
__%(.+)%__
Where '(.+)' would be the ID of the region to be created. Any regex pattern can be used here. Patterns should be constructed like so (if our replacement pattern were '__%(.+)%__'):
__%name_of_region%__
The generator would interpret this as a region like so:
regions[name_of_region] = name of region
During the generation process, it will replace those patterns with the appropriate PHP code to output the regions.
Theme ID
This should be the computer readable format of the name of your theme. If you want your theme to be called 'Wicked Local Plymouth', your ID should be:
wicked_local_plymouth
No spaces or whacky characters here, please.
Theme name
This is simply the name of your theme. This will show up on the themes listing page (/admin/build/themes).
Theme description
Just the description, and will also show up on the themes listing page.
The generation process
So, with those fields set, clicking 'Generate theme' will do the following:
That's about it. You'll need to be sure Apache has write permissions on /sites/all/themes.
Thinking ahead, not only is creating these Drupal themes quickly and efficiently very useful, but the management and update process of those Drupal themes would also be significantly useful.
Since we want one central location where we will manage our site templates, we only want to have to make modifications to that one place. Thus, we'll need Drupal to keep tabs on these automatically generated themes, and update them accordingly if changes are made to the root template. This should be a fairly straightforward enhancement to this module, allowing for manual theme updates, as well as updates run on cron.
Again, this module is in its infancy, but judging by the amount of usefulness we've found it provides already, there will likely be many enhancements to this project.
Download the Theme Generator module.
My to-do list for this module:
Finally, my feature wishlist for this module (in no particular order):
That's about if for now, let me know your thoughts!
11 Comments
Perty
Very, very cool. I'll be giving it a whirl tonight.
nice, this could be very very useful to me. let us know when you get it up on d.o!
Just an update - as of 11pm last night I updated both the module zip file, as well as the pastie version.
Specifically, I rewrote much of the way replacements are handled. Fixes included:
- Handle templates only defining one region
- Switched the way variable names are generated from patterns to eliminate redundancy
- Added the output of $title, $tabs, $messages, $help directly before the output of $content
There are still issues with:
- Attempting to replace content using a regex that does not return a backreference
- Handling the generation of variable names more efficiently
Also fixed a bunch of stuff related to Drupal coding standards, including:
- Addition of commas at the end of the last item of Array lists
- Switched tab width to 2 spaces
Module updated including the following:
- Massive commenting overhaul according to Drupal standards
- Code ran against code-style.pl
- Reordered function locations in the file to be more logical
I am trying to run the generator on my template.html file. it doesn't seem to make a box tpl file, or module, or anything else. just the info file and the page tpl file
James,
Yes, currently that's the only functionality of the generator. Eventually, the module will also build the necessary scaffolding template files using the Zen theme markup to provide the theme with more customizability. With just a page.tpl.php file, however, the theme will still function just fine, since Drupal uses default theme functions for nodes, blocks, etc.
Also, I'll be putting the module on Drupal.org sometime early next week, where I'll be taking feature requests as well as gauging support for co-maintainers once our clear goals are established for the module.
Thanks!
Nick
This module has been moved to Drupal.org for support, feature requests and bug reporting. Please direct any and all communication to the project's new home on Drupal.org:
http://drupal.org/project/theme_generator
Nick
i try this module, but only this massage appaer: 'No regions found to generate.'
What i need to do?
im a drupal newbie :-)
thanks
maczkojanos,
Within your HTML template that you're pointing to, you'll need to define your regions like so:
__%name_of_region%__Nick
Post new comment