Monday, October 27, 2014

Drupal - Rebuild permissions

Because I always forget where to find the rebuild permissions button in Drupal, this is my reminder

drupal 6   /admin/content/node-settings/rebuild
drupal 7   /admin/reports/status/rebuild

I actually do not have permission to use this image....

Thursday, October 16, 2014

Drupal 7 - apache solr - how to add an total results count to your results

Somehow I naturally expected a total results entry somewhere in the arrays solr sends me, but I could not find it.
So, what is so weird about wanting to show the number of results?

The solution is of course rather simple, like everything is simple in hindsight, but nevertheless it took me hours to come up with it. Mostly because I was googling through endless hits more or less about this problem and maybe I should try to catch some more sleep....

The solution is to lift the value from the GLOBALS array.  Add  $GLOBALS['pager_total_items'][0] somewhere to a variable in a preprocess hook or simply print in in your template file like thus:

<div class="counter"><?php print $GLOBALS['pager_total_items'][0].' results'; ?></div>

Thursday, September 18, 2014

Drupal 7 - Picture - Adding captions to responsive images

I've setup an D7 site (a D6 upgrade) with Picture and Breakpoint where I want to show a caption for some of the images. In the  D6 version used the title attributes as captions for some of the images with a phptemplate_imagecache function. (Depending on the image style used.)

Oh caption, my caption
There are some modules (,,, etc) which give you the possibility of adding a caption field, but as I do not want to build another module to convert all existing title tags to these caption attributes, and also need a solution for non javascript browsers, I needed something more basic.

Based on the specific imagestyle or specific picture mapping, decide to render or not render a caption. The content of the caption is the content of the title attribute.

Add a theme function to your theme's template.php
The idea is to simply override the theming function in picture (which is the module I use for my responsive images)

// this theming function assumes that the picture module is installed
function THEMENAME_picture($variables) {
  // first produce the  standard picture output
  // we only add titles to the images where a specific picture mapping is defined
  if (array_key_exists('breakpoints', $variables) && array_key_exists('title', $variables)){
     if ($variables[breakpoints]['custom.user.normal']['1x'][image_style] =='rsp_adviesplaatjecustom_user_normal_1x'){
        if ($variables['title'] !=''){
           $output=$output.'<div class="image-caption"><div class="image-caption-text">'.$variables['title'].'</div></div>';
  return $output;

Wednesday, August 20, 2014

Drupal - Omega 4.x - layouts - how to create a layout and add a sidebar (or anything)

Lets start with a giant disclaimer - my lawyer advised me thus, to always start with a disclaimer, even if I am just entering a supermarket or visiting a friend for a coffee:
I don't know if all here under is the correct way to proceed.
Adding a layout as shown in the leveltuts tutorials did not work. But I  probably just forgot a step, multiple times, or multiple steps at different times in the process. Anyway, I decided to do some low level cortex manipulation and lo and behold, that worked.
Low level cortex being simple copy-paste and renaming magic.

I wanted a layout with an extra region in it, and it seems that the best way to do that is to add a layout to your omega subtheme. As I am still novicing into the omega 4.x sass setup, I could be totally wrong on this. 

Well, anyhow, here my cookbook:
1. Create  (if not already there) a folder 'layouts' in your omega subtheme folder
(So in my case the subtheme is called rli2015 and the layouts folder in /sites/all/themes/rli2015/layouts)
2. copy the folder simple from your omega base theme to the layouts folder you just created (sites/all/themes/omega/omega/layouts/simple)
3. Rename this folder to what you wanna call your layout.
I called it allpages as I wanted to create a layout I can use over the whole site
3.1 rename the folder to your layout name. In this aexample allpages.
3.2 rename the file to
3.3 rename the file simple-layout.tpl.php to allpages-layout.tpl.php.
3.4 In the change:
3.4.1 name=allpages
3.4.2 description = whatever text you want here
3.4.3 preview= allpages.png (if you want to make an image for this layout, you can also leave it out)
3.4.4 template=allpages-layout
(has to be what you named your tpl file under 3.3)
3.4.5 Stylesheets (you can leave this one out, or simply add an empty one for later use)

; Stylesheets 
stylesheets[all][] = css/layouts/allpages/allpages.layout.css
3.4.6 Add a region under the regions section

; Regions
regions[branding]       = Branding
regions[header]         = Header
regions[navigation]     = Navigation bar
regions[highlighted]    = Highlighted
regions[help]           = Help
regions[content]        = Content
regions[sidebar_first]  = First sidebar
regions[sidebar_second] = Second sidebar
regions[sidebar_third] = Third sidebar
regions[footer]         = Footer
3.5 Also add this region to your inc file under your subtheme itself, in my case
regions[sidebar_third] = Third sidebar
3.6 In your tpl file (allpages-layout.tpl.php) add the region you just added where you want it rendered

<?php print render($page['sidebar_third']); ?>
NB! If there is no content in the region, the region will not be rendered
3.7 Copy the omega/sass/layouts/simple folder to your custom theme sass layouts folder
3.7.1 Rename simple to allpages
3.7.2  Rename simple.layout.scss to allpages.layout.scss (has to be the same as the one you declared under 3.4.5)
3.7.3 Strip it of all its content.
4. Go to admin/config/development/performance.
5. Clear all caches.
6. Go to appearance.
7. Choose the settings of your subtheme.
(in my case admin/appearance/settings/rli2015)
8. Enable layout extensions.
9. Select your custom layout and save the configuration.

After that you have a html output with your extra third sidebar (providing you've added content to that sidebar....)

If you have guard (bundle exec guard) running on your subtheme directory the css file should be automatically created under /sites/all/themes/rli2015/css/layouts/allpages.
If not, add the allpages.layout.css file by hand.

I had the problem that guard (bundle exec guard)
stopped working. It simply did not compile.
Dunno why...
Instead of that I ran compass watch multiple times in the same directory, stopping it with ctrl-c. And after some iterations of that I got messages about changes made. And after that, bundle exec guard also ran again. Dunno why....


Friday, August 1, 2014

Drupal 7 - Omega 4.x with Sass - how to add a css to the theme

(this is a post under construction, more or less. I am digging into the omega4 -Sass - theming setup framework. Just rather pissed off by spending two whole days on installing RVM - one of the prerequisites for using Sass - on my mac. Will write a blog about that process, when I don't feel the need for strong langiuage anymore. This is just a post about simple tasks you wnat to perform and which nonody seems to want to add to the documentation. Probably because only fools like me don't know how to perform these simple tasks....)

This post supposes you have an omega 4 subtheme installed and the Sass environment set up and you have the guard running on your subtheme folder (bundle exec guard)
(see f.i.

1. Open your subtheme info file (in this example my subtheme is called rli2015, so we open
2. Add a line in the stylesheets section
 stylesheets[all][] = css/
3. navigatie to your sass folder (in this example themes/rli2015/sass) and add a file
4. Imediately a file will me generated in your css folder
5. This css file will also be added to your rendered page

Sunday, July 27, 2014

Drupal - Got error 28 from storage engine query

So I had one site with suddenly error 28.

Warning: Got error 28 from storage engine query: SELECT DISTINCT b.* FROM blocks b LEFT JOIN blocks_roles r ON b.module = r.module AND = LEFT JOIN i18n_blocks i18n ON (b.module = i18n.module AND = WHERE (i18n.language ='nl' OR i18n.language ='' OR i18n.language IS NULL) AND ( b.theme = 'seven' AND b.status = 1 AND (r.rid IN (2,4) OR r.rid IS NULL) )ORDER BY b.region, b.weight, b.module in /var/hosting/sobibor/ on line 148

As of the site contents I usually first suspect a hacker with extreme right wing sympathies to have destroyed part of the site.
But the issue was very simple and unbiased: Not enough diskspace!

Right wing disk thrower

Drupal 6 to Drupal 7 migration of Audiofields: a missing filefields problem

During a recent D6 to D7 upgrade I got stuck on an irritating problem. Although the filefield module has been included in D7 core, during the migrate fields action the system kept presenting me with the impossibility to migrate filefields from the d6 definitions.


  • Missing field module: 'filefield'. This field cannot be migrated.
  • Missing formatter: The 'hidden' formatter used in 1 view modes for the field_advies_audio field is not available, these displays will be reset to the default formatter.

    The reason for this problem is that the field has a widget_type audiofield_widget and a widgetmodule audiofield. So I naturally tried to upgrade the audiofield module, but this does not solve the problem. CCK migration simply refuses to migrate these fields. Dunno why exactly.  (Instead of Missing field module: 'filefield'. This field cannot be migrated. a better error message would be: Won't do audiofields. Don't fucking like them. Sue me.)

  • Whaaaat??


    Manually change the widget_type to filefield_widget and the widget_module to filefield. You can do this via phpmyadmin for instance. Or to do this for the multiple audiofield we've defined, run this query

    update {content_node_field_instance}
       set widget_type = 'filefield_widget', widget_module = 'filefield'
              where widget_module = 'audiofield';

    If you run it directly use the table name with prefix. The above you can run in Devel.

    I will post here lateron how to adress the presentation in the final upgraded site.

    Tuesday, April 8, 2014

    Drupal - cron memory exhausted trails and tribulations

    Having a Cron job
    So, sometimes you simply miss a cron fail. That happens. Your client calls:
    Hey, the notifications stopped.
    New pages don't show up in the search results.
    Collections not getting indexed.
    A service is down.

    And I always forget how to solve it. I just rumble along. Sometimes I increase the memory limit, the execution times never works (is hard coded in common inc I believe to be 240 or something), shut down one of the modules, ini_set this, ini_set that,  prune some tables, pray, curse.....

    I must say I utterly dislike cron fails as they are so terribly boring. So  I wanted to write an eloquent and excellent blog about all my cron resolving adventures, just to add some meaning to this annoying part of my life. But then, opening my development and maintenance logs, I remembered: There is no need for me to write anything.
    If you have a cron problem, simply visit and tell them I sent you.

    Thursday, March 20, 2014

    Drupal - access denied page after login

    Today I got an access denied page after login, just rerooting me to the login page. I 've got this before, on a number of very different sites. Usually this problem coincides with big other problems in the website concerned, so you really can do without this annoying access problem.
    There can be an infinite number of causes: Crashed sessions table, changes in apache, php upgrades, butterflies in Australia....
    Here is my short track to quickly regain access to the site:

    Solution 1
    Truncate the sessions table and then try again

    It is perfectly save to truncate the sessions table although all currently logged in users are then logged out.  The sessions table keeps track of all user sessions on your site. It has an entry for every user/browser combination that's logged in to your site. (Logging in from firefox and from chrome creates two entries in this table, and the same goes for logging in from different devices)

    Solution 2
    Add cookie domain setting to your settings.php file, like this
    $cookie_domain = '.mydomain.ext';
    And then try again

    (see also

    Solution 3
    When your sessions table is crashed, simply repair table and try again

    Solution 4
    Find a religion that suits you bests and make an offering to the God or Gods who are proclaimed to be most helpful to developers by this chosen religion.....

    Drupal - unable to overwrite the settings.php

    The funny thing about drupal is it protects your files and permissions automatically. But sometimes I feel like a pilot in a plane where I do not know some of the automation.
    For instance, sometimes you want to overwrite the settings.php file and you do not have the permissions as the FTP user. Here is first a simple set of steps how to proceed.

    You want to make changes to settings.php but are not allowed to overwrite.

    Drupal automatically sets the following permissions on your default folder and on your settings.php therein

    dr-xr-xr-x 3 {user} {group} 4096 Mar 20 12:31 default
    -r-xr-xr-x  1 {user} {group} 10516 Mar 20 10:27 settings.php

    The user being your ftp user then is not allowed to write into the default folder, nor to overwrite the settings.php file.
    Which is good, of course, but we temporarily want to be bad.

    What you want is to change the permissions, overwrite settings.php, and then reset the permissions to what they where.

    1. login to your server shell and navigate to your site
    cd /var/www/vhosts/domain.ext/sites
    2. change the permissions of the default folder
    sudo chmod a+w default
    3. enter the default directory
    cd default
    4. change permissions of your settings.php (oooow, spooky...)
    sudo chmod 777 settings.php
    5. Now overwrite the settings.php with your FTP program.6. To restore the permissions of the default folder and the settings.php file just login to your site, go to administer -> reports -> status report

    7. running ls -l in your terminal will show you that all permissions are magically restored. Hail Drupal.

    Step 6 is maybe like a braindead way of restoring the permissions, but it is the good way of doing this, let drupal handle this stuff, and you point your brain to problems that are interesting on a human level....

    Tuesday, February 25, 2014

    Drupal 7 - Creating a contentype with repeatable expandable fieldcollections

    I want to make me a simple to manage contenttype containing fields and field collections that I can present as collapsible fields.
    On page load the field value will be hidden and the labels will be shown as clickable links. Clicking them will expand the content of the field.
    I want to use field collections in the same way, but there give the maintainer the power to edit the 'label'. Adding fieldcollections of the form (title, content) should do that. On page load the title will be shown as a clickable link, and clicking on that will expand the content.

    For the collapsing functionality we use, as it is already there, ctools.

    1. make a field display collapsible with ctools
    In general using ctools it's very easy to make a field display collapsible.

    1.a Put this function in your template file
    function MyTheme_collapse_content($c_content, $collapse_heading) {
       print theme('ctools_collapsible', array('handle' => $collapse_heading, 'content' => $c_content, 'collapsed' => TRUE));

    1.b  In the field template file simply put this code
       $collapse_heading = $label;
       foreach ($items as $delta => $item): 
         $c_content.='<div class="field-item ';
         $c_content.=$delta % 2 ? 'odd' : 'even'; 
         $c_content.=' '. $item_attributes[$delta].'>';
         $c_content.= render($item).'</div>';
      MyTheme_collapse_content($c_content, $collapse_heading);

    1.b.1 template naming
    If you worry what to name the field template files simply check!field!field.module/function/theme_field/7

    Now, how to accomplish this task for the fieldcollections?

    2. Add a fieldcollection field to the contenttype
    In this example called Page or machinename field_event_sub_page
    2.1 Add two fields to the fieldcollection
    2.1.a text field page_title
    2.1.b  and a textarea page_text (filtered html)

    Now you can add field collections to the node consisting of a text field (page_title) and a textarea (page_text).
    Now I want these text fields  (the page_title) to show as links, and clicking on these links should open the corresponding textarea's (page_text), giving me a single ode behaving more or less like a book with only two levels.

    Using the ctools collapsing the problem is now reduced to getting the page_title and page_text field content in the $c_content and the $collapse_heading variables in a theme function like the above:

      MyTheme_collapse_content($c_content, $collapse_heading);

    This is usually a very annoying deconstruction of the fieldcollection instance, I must say I get lost a lot of times.
    But now I found this very elegant solution by Mike Minecki

    2.2  put these functions in your template.php

    function MyTheme_preprocess_field(&$vars, $hook) {
      $element = $vars['element'];
      if (isset($element['#field_name'])) {
        if ($element['#field_name'] == 'field_event_sub_page') {
        $vars['theme_hook_suggestions'][] = 'field__event_sub_page_collected';// waar is dit eigenlijk voor nodig

         $field_array = array('field_fesp_linktitle', 'field_fesp_text');//must match the fields you added to the field collection
        rows_from_field_collection($vars, 'field_event_sub_page', $field_array);

    function rows_from_field_collection(&$vars, $field_name, $field_array) {
      $vars['rows'] = array();
      foreach($vars['element']['#items'] as $key => $item) {
        $entity_id = $item['value'];
        $entity = field_collection_item_load($entity_id);
        $wrapper = entity_metadata_wrapper('field_collection_item', $entity);
        $row = array();
        foreach($field_array as $field){
           $row[$field] = $wrapper->$field->value();
        $vars['rows'][] = $row;

    2.2   Put this rendering in your fieldcollection template file
    In this example that would be the field--field_event_sub_page.tpl.php template file.
       foreach($rows as $row): 
          $collapse_heading $row['field_fesp_linktitle'];
          $c_content $row['field_fesp_text']['safe_value'];
          MyTheme_collapse_content($c_content, $collapse_heading);

       endforeach; ?>

    Accessibility - Using images as a link conforming to Dutch webrichtlijnen overheid

    As I always forget this, here is a micro-blog-post about this requirement for the Dutch Govermental organisations. Governmental sites need to comply with the 'Webrichtlijnen overheid versie 2'.

    It is allowed to use an image as the content of a link, as long as the image has a useful and descriptive alt text.

    Ref. criteria for succes 2.4.4, 2.4.9 en 4.1.2


    Thursday, February 6, 2014

    Drupal - Accessibility: ways of adding language attributes to parts of your text that differ from the main page language

     One of the accessibility rules, especially targeted to screen readers, is that text parts written in a language different  from  the main page and navigation language should  be tagged (or more correctly 'attributed') with this other language, so the screen readers know when to use what language.

    I remember the fun we had on the Institute for Plasmaphysics Rijnhuizen (Nieuwegein, the Netherlands) making the first Macs with screenreaders   read out  a Dutch text. As the reader was only able to read english texts a perfectly readable Dutch text came out as Jibberish spoken by someone who's been drinking Jenever (dutch booze) all day while eating a tuna-sandwich.....

    Here I show two ways how to achieve this, (that is adding the attributes to the tags, not the tuna-sandwich part).
    Case 1 in Drupal 6 wysiwyg with Tinymce, and Case 2 in Drupal 7 with CKEditor.  Goal is to select a part of the html,  and add a language attribute. Or to the containing tag or to add a span tag...

            <tag>Lorem ipsum and so forth</tag>

    should become

          <tag lang="en">Lorem ipsum and so forth</tag>

    CASE 1      Drupal 6                                                

    D6 site, with the WYSIWYG module using tinymce
    1. Add html attributes button to your RTE
    1.1 Go to Administer > Site configuration > wysiwyg profiles
    1.2 edit any of the profiles where you want the users to be able to add the language attribute
    1.3 Open 'Buttons and plugins'
    1.4 Check 'HTML attributes'
    1.5 Save

    Result: How to add a language identifier
    In your browser you can now find a new button

    a. Select part of a text and click this button
    This opens up a popup screen where you can add attributes

    b. Behind language add the language identifier for the language usedf.i. en (english), nl (dutch) etc.
    See also
    c. Click insert
    And the language identifier is added to the tag containing the textpart.
    If you add an identifier to a part where a mother tag already contains the same language identifier, the identifier is not added. This seems logical because there is no need for this identifier at all.

    Problem: adding lang attribute to inline tags
    You cannot add attributes to inline tags like <span>
    This is really annoying cause you have lots of cases where the other language words or sentences are inline with the other text. Like when I tell you the Dutch word for annoying is irritant.

    Solution: use <em>
    But a solution is to use the <em> tag and css. The html attributes will be added to the <em> tag.
    a. First make the text part italic!
    b. Then select part of the inside italic text, not all, and add the language identifier.
    c. Save

    If you select the whole italic part (including the em tags), the system will find the nearest containing tag and add the language identifier to that one.
    d. To avoid the other language being shown as italic, you can target this em element with the language selector in the css.

    So like when you main language identifier is english

              em:lang(nl),em:lang(fr), em:lang(ge)


    Adding the em:lang(en) in the above css would change all em to normal, because the language selector simply looks for any language identification, may it be in the tag itselve, or in the header of the document like <html lang="en" dir="ltr" xml:lang="en" xmlns="">

    <em lang="zh-Hant">希望對您有所助益<em>

    There is a major problem in Drupal concerning these attributes. From the accessiblity viewpoint, it should be very simple to add a language attribute to every element. But I have to figure out yet how to add a language attribute to a field like the title. (Or the resulting display of this in a nodereference rendering)
    There are two language layers here you have to consider: The field language, which simply identifies in which languagepart of the site you want this field to show up, so in case of content translation this is the context language of the container entities, in case of field translation it is the [lang] part of the field.
    For instamce, Being Dutch have nodes with partly Dutch and English titles: "Presentatie resultaten onderzoek 'Designed to Last' op 8 oktober 2014".
    Trying to convince my governmental organisations to change the titles of their reports to solid Dutch does not work, so I have to deal with this. The result should be

    <h1>Presentatie resultaten onderzoek <span lang="en" xml:lang="en">'Designed to Last'</span> op 8 oktober 2014</h1>

    I solved it using a jquery on the specific nodes with these kinds of titles, but thats rather an unsatisfying solution.

    CASE II : Drupal 7                                                   

    So, I figured out how to do this in Drupal 7 with CKEditor.  There is a CKEditor plugin you can install and download
    Of course, because why should  life be easy, there are some irritating bugs or features or whatever....

    0. Plugin
    You can download the plugin from here

    In the example hereunder my module path  is
    and I've installed the ckeditor itself in

    1. Now make a folder 'languages' in 

    2. put plugin.js and icon.png in this folder

    3. open ckeditor.config.js in the root of your module and add these lines

    = 'languages';
        // The languages you want to support (code:name).
        config.language_list = [ 'de:German''fr:French', 'es:Spanish', 'it:Italian', 'en:English' ];

    NB! This is different from the installation instructions on GIThub.

    4. Clear your Drupal cache AND clear your browser cache
    (the ckeditor does not clear its javascript files on the normal Drupal cache clear)

    5. Go to your CKEditor settings and add the languages button to your editor
    (In an older version the visual UI did not work, but the manual did. Now this seems ok)

    6. Content filters
    You'd probably might have to change you content filters to allow for these attributes, but apart from that it should work. I had to add

         p h1 h2 h3 h4 em span [*]

    under the extra allowed content in the ckeditor setting for my filtered and full html
    For more infor on this see!/guide/dev_allowed_content_rules

    7. Rejoice in many languages
    And yes, ganz lustig,  it works

        And yes, <span dir="ltr" lang="de" xml:lang="de">ganz lustig</span>, it works

    Tuesday, February 4, 2014

    Make two divs equal height with jquery (in Drupal)

    One problem I often face is that I have two divs, a content div and next to it another div with a menu, or links to related content or whatever. And I want both divs, f.i. #content and #rightbar, to be equal height, but they are added loosely to the html bacause the html needs to be responsive.  Sometimes you can get it working with css, but lots of time I get lost.
    One solution is to simply compare the two and make them equal height with a javascript/jQuery function.

    function equalHeight(one,two) {
       var tallest = 0;
       if (tallest < two.height()) {


    Call this function in a document ready like so

    (function ($) {
    // drupal jquery wrapper
         $(document).ready(function() {


         function equalHeight(one,two) {
             var tallest 0;
             if (tallest two.height()) {

    // emdof drupal jquery wrapper

    Monday, February 3, 2014

    Lost books of the Bible: The book of Metatheria

    There must be a lost biblebook which explains why all marsupials went straight to Australia after Noahs Ark stranded. 'Bye Noah, thanks for saving us!' And none of them decided to stop somewhere halfway in Afghanistan or China.

    Well then, except for the opossum and the shrew opossum which went to respectively North and South America, and some lazy marsupials which, crossing Indonesia, decided to take a break and simply stayed there.

    And they thus spoke to them, saying:  'Ah, don't worry, we'll cach up later....'.    But that's all explained in this lost Bible book: 1 Metatheria 2:7

    Saturday, January 25, 2014

    Life and Death questions: Where to write the copyright in an image tag? In the Alt or in the Title attribute?

    One of the important questions in my life is where to write the copyright statement in an Image tag. It's sometimes keeps me awake at night. It is one of those daunting questions which are not answered by one google query. For lots of use cases adding the copyright statement as a caption under the image is not an option.

    The copyright sign mirrored

    The alt attribute should contain a description, in 150 characters or fewer,  preferably a description in the context of the embedding page, of the visual content of the image. This is the part that mr. Google indexes. So it is the SEO part of the image as well as the visually impaired part, targeted at screenreaders and the like.

    The title contains the text that appears in the tooltip when you move your mouse over the image. It should contain additional info, like if the image is linked, where the link will lead you.

    The Answer: The Title attribute
    As the copyright is not a visual description of the image, you should therefore add it to the title attribute. This is also suggested by w3c.

    But on the other hand, as you probably would like to buzz the photographers name around on the internet, and would like the search engines to find all the images belonging to a certain copyright holder, the alt attribute is also used for the copyright statement by lots of sites.  The alt text should never begin with the copyright statement, but it is used a lot.
    I do not know if there are any accessibility rules targeting the credit statement specifically for this matter.
    Reading all information I suppose that from the viewpoint of accessibility it is a bad solution, but from the viewpoint of the search engines, it is a good solution.

    Friday, January 24, 2014

    Drupal 7 - specifying different output per role type in a template

    Lot's of time I want content or links hidden for unauthenticated users but shown to the site administrators or other user roles. As I always forget how I do it, and then search in old code or ask my old friend mister Google, here's a little blog about how to:

    In the template, for instance a field template for a field in a view, add this code.

    // load the global user object
    global $user;
    // Check if  user has (f.i.) the 'administrator' or 'contributor' role.
    if (in_array('administrator', $user->roles)||in_array('contributor', $user->roles)) {   
        // do something
    } else {
       // do something else
    NB! I use this on small sites. It is fast and easy.

    For larger sites solution you should define these things using permissions, otherwise the site will in time become unmaintainable.  Adding a permission to another role might then mean changing twenty template files or so.

      // user_access default takes the current logged in user as user object
      if (user_access('permission x')) { 
        // do something
      } else  {
       // do something else

    Because setting up the normal permissions may become very complex, you can also add custom permissions with this module and use them in your template file for this kind of functionality.