Drupal

Portland January Meetup Tonight

Cookies and Lullabots at Hotel deLuxe

Just a little reminder for the Drupalers in the Portland/Vancouver area that the Lullabot folks will be hosting a meet-up this fine evening (Wednesday, January 9) at the Hotel deLuxe.  If bathing in a sea of Drupal experts while eating free cookies isn't enough, Jeremy and I will be there, too.

 

 

Miscellaneous:

The Power of template.php

A few techniques to help your designers.

Theming a fresh Drupal site always gives the designers true glory. Well, its time that I help out my fellow programmers. After all, without us, its just a pretty drupal core.

First things first. I'm assuming that you and the designer are working on a clean theme, like zen. I'm also assuming the use of Drupal 5. Most of the code is available via drupal.org.

So what kinds of things can you do?

Custom id and class tags

The most important thing to know is that Drupal allows the modification of theme functions within this file. This means any function within a module or within the Drupal core that begins with name theme_xxx can be hooked into and modified to include elements to assist the designer, i.e. adding 'id' or 'class' tags.

Let's say, for example, you'd like to modify the menu items. Your designer wants to be able to add special attributes to each menu item, but needs a unique id tag for each list element. Because there is a theme_menu_item function in the core menu.inc file, we can simply create a phptemplate_menu_item function in template.php that overrides how the menu item is displayed. This avoids touching the actual core function (a big no-no in Drupaland) and keeps our mods in one location as upgrades are performed, assuming your template.php file is in the sites -> default -> themes directory (which it should be).

To add custom id tags to each menu item, as well as add an 'active' class when the user is on that particular page, try:


/**
* Implementation of theme_menu_item().
*
* Add active class and custom id to current menu item links.
*/

function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
$item = menu_get_item($mid); // get current menu item

// decide whether to add the active class to this menu item
if ((drupal_get_normal_path($item['path']) == $_GET['q']) // if menu item path...
|| (drupal_is_front_page() && $item['path'] == '')) { // or front page...
$active_class = ' active'; // set active class
} else { // otherwise...
$active_class = ''; // do nothing
}

$attribs = isset($item['description']) ?
array('title' => $item['description']) : array();
$replace = array(' ', '&');
$attribs['id'] = 'menu-'. str_replace($replace, '-', strtolower($item['title']));

return
'

  • ' .
    menu_item_link($mid) . $children ."
  • \n";
    }

    The key to this function is the line:

    $attribs['id'] = 'menu-'. str_replace($replace, '-', strtolower($item['title']));

    This creates a value in the $attributes array with a key of 'id' equal to the value of string 'menu-' concatenated to the actual name of the menu item. As long as each menu item has a unique name, a unique id is generated and the style can be crafted accordingly.

    Different designs for different pages

    Maybe you have a front 'splash' page, a 'home' page, and then the rest of your site. This is typically true for new startups providing a web service. You'd like new visitors to have a very simple experience showcasing your service, logged-in users to have an array of links to choose from, and something different once users are using the service.

    By default, pages and nodes will use the page.tpl.php and node.tpl.php, respectively. To have your 'front' and 'home' pages use a different template file, you need something to translate what page the user is on (via the url) and select the appropriately named file. As outlined in the theme developer's guide of drupal.org, the template.php file can accomplish this within the _phptemplate_variables() function, specifically within the switch case of 'page'. If you're using the localization module, you'll want to edit the function slightly to allow for the prepend of the language:


    if (module_exists('path')) {
    $alias = drupal_get_path_alias($_GET['q']);
    if ($alias != $_GET['q']) {
    $suggestions = array();
    $template_filename = 'page';
    $alias = explode('/', $alias);
    array_shift($alias);
    foreach ($alias as $path_part) {
    $template_filename = $template_filename . '-' . $path_part;
    $suggestions[] = $template_filename;
    }
    }
    $vars['template_files'] = $suggestions;
    }

    Views Theme Wizard

    As you create your views, customization can add more depth to your design. Although you may want to create multiple views that group by specific elements, each view doesn't need to look the same even if they function the same. An example would be creating a view that showcases events and groups them by date and one that showcases events and groups them by category.

    Answer: Use the views theme wizard. This function automatically generates the proper code for you to place inside your template.php file and create the proper template files for your designer to manipulate.

    Miscellaneous:

    Coding:

    Drupal Admin Theme

    Designed as an admin theme yet can be used as a regular theme

    I started working on an admin theme for Drupal over two months ago in my spare time and just got around to packaging it up offering it up for download. I've used it on a a few client's sites and they seem to like it so hopefully someone else can get some use out of it.

    As you may or may not know Drupal has the ability to switch from your site's theme to an admin theme when the user is logged in as an admin and in the "/admin" URL. Typically I used the Garland theme for this purpose as it looks different than any theme I've made so it's easy to tell if you the user are in the "admin" area as opposed to viewing a site. Not to mention the Garland theme looks and and works great too.

    The only annoyance I've had with switching over to an admin theme is that when you go to edit a page it takes you to the "edit" page but still uses your site's theme. This can get confusing as you are in the admin menu but yet your theme isn't using the admin theme you selected. To fix this I created a module for my theme which uses my Drupal admin theme for the "add", "edit" and "delete" pages.

    Screenshot of my Drupal admin theme:
    Drupal admin theme

    So if you download my Drupal admin theme be sure to install the module for it as well. Also be sure to activate it through the "modules" page. It probably won't work for everyone but it seems to do the job for me and my clients so far. Feel free to rip it apart and make it your own.

    Ready to give it a try? Go ahead and download my Drupal admin theme.

    You can also grab the module here.

    If you like the theme or have any ideas on how to improve it please let me know as it's still a work in progress. I'm pretty sure I'll update it to Drupal 6 when that becomes officially released. It can also be used as a regular theme for your site - not just an admin theme.

    Miscellaneous:

    Coding:

    Simplemenu Module Customizations

    Making a great Drupal admin menu better

    I'm a big fan of the Simplemenu module for Drupal as it's quite a time-saver when developing a site. It's really handy to have the entire admin menu right at the top of each page.

    Clients also love it for it's ease of use and they don't have to navigate to "/admin" everytime they log in and want to make a change to the site. Now they can just hover over the option the want on the top navigation bar accross their browser and drill down to the specific page they want. Very handy and much quicker than manually drilling down to each page. It's been a real time-saver for me so far.

    As soon as I installed Simplemenu I knew it was a module I was going to use for quite some time. That's the reason I wanted to skin it and make it look/work better for me and my clients. I also implemented it into a custom Drupal admin theme I am working on which I will release real soon. So check back for that one early next week.

    My custom menu:

    Custom Simplemenu

    Although my changes are minor I would stil like to thank the author for creating such a useful module written by Ted Serbinski, aka, m3avrck. I took what he had supplied and modified the CSS, JavaScript (just a little) and added a few new images.

    These changes look and work great in Safari, FireFox and IE7. It works in IE6 just fine but the top level menu background doesn't stay colored when you drill down to the sub menus. I'm sure it's an easy fix but I didn't bother researching it much since..well it's IE6. If anyone wants me to fix it then please let me know and I'll give it a shot.

    So for now - if you'd like you can go ahead and download my modified version of the Simplemenu module for Drupal.

    Please direct all feedback/comments/questions to me in this thread so I can update and improve it as needed.

    Miscellaneous:

    Drupal For Facebook

    "Bring the Power of Drupal to Facebook Applications"

    Normally wouldn't post a link to something without testing it out ourselves first (that's just not how we roll), but this one seemed worth sharing right away.

    Saw this link come across Scoble's shared feed and was absolutely intrigued.   Seems one Mister Dave Cohen is working on a method for throwing your existing Drupal content over onto your Facebook account.  Also apparently will give Drupal developers a handy and familiar way to create Facebook apps. Pretty damn cool idea.

    If you want to see it in action, take a look at http://www.drupalforfacebook.org and compare it to http://apps.facebook.com/drupalforfacebook/.  Like Nick O'Neill mentioned in his original post, Cohen's ported his Drupal install into the Facebook app.  Looks good.

    In the interest of full disclosure, I should mention that I'm usually pretty down on the social networking stuff.  I have a Facebook account, but really haven't used it for much (feel free to look me up if you need a friend).  I haven't had that Facebook epiphany so many of its fans have experienced, and I don't really get the hype. 

    All that said, though, coming from a Drupalistic perspective, I think this is pretty damn cool.  Gives those of us with a little Drupal experience a backdoor into the apparently ever-so-fabulous world of Facebook .  Wouldn't be a bad idea for the Facebook people themselves to fund some of Cohen's work to get this going...  Seems to be in their best interest to harness the Drupal vote.  Frankly, the idea of a Drupal site (like this one...) being seemlessly integrated with Facebook makes me all tingly.

    Web 2.0:

    Miscellaneous:

    Pages

    Subscribe to RSS - Drupal