Surrey Drupal Meetup: April 14, 2011: How to Use Template.php to Power your Drupal Themes

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
katy5289's picture
Start: 
2011-04-14 06:30 - 09:00 America/Vancouver
Organizers: 
Event type: 
User group meeting

Topic: Drupal Theming - What is template.php and how do I use it?

RSVP: Please RSVP here: http://www.meetup.com/surrey-drupal/events/16607568/

* What is the talk about? *
We'll explore the purpose of the template.php file in theming as well as the relevant Drupal API functions. We'll then delve deeper into creating the most basic functions needed in the file. Finally we'll explore the process of reading the code of other modules to help you find the places where you can change their output via template.php

* Who am I? *
Colin Calnan is a Senior Developer working with Raised Eyebrow Web Studio (http://www.raisedeyebrow.com) in downtown Vancouver. He's been working with PHP since 2000 and Drupal since 2007 and has a undergraduate degree in Computer Science with a masters degree in Design and Digital Media. He's themed over two dozen sites since starting Drupal theming and built and themed websites such as:

http://www.policyalternatives.ca
http://www.analyticdesigngroup.com
http://www.cfenet.ubc.ca

* Who should attend? *
Drupal themers of course! If you've been given a mockup and need to make a functioning Drupal site, this is for you. Hobbyists or anyone who has lost time and hair trying to figure out how to change the output of modules are also welcome.

* What will I take away with me? *
You'll leave feeling more confident in your ability to create themes in the future. You'll know more about the Drupal API and how to search it. You'll have the confidence to open module files and have the ability to find the theming stuff you're looking for. You'll be one step closer to becoming a Drupal Rockstar themer, and you'll meet lots of nice Drupal people while you're there.

Drupal Showcase (AKA Lightning Talks): We want you to showcase your latest project or share a great development tool with our group. Come prepared to give a short 5 minute talk on any Drupal related topic. If you want to use a laptop to demo a website or control panel, please be sure you have the necessary cable to connect to the overhead projector. Please contact Katy@seascapewebdesign.com to schedule your showcase.

Drupal Q&A: Bring your questions on anything related to Drupal from how to do something technical in PHP to what modules are needed to implement a feature you need.

Cost: While there is no cost for this event, it would be great if you can come prepared to order something (some of us order dinner, some just drinks) along with a 15% gratuity as we really want to keep up a good relationship with ABC as they've been great in allowing us to book their conference room.

Comments

Specific theming dilemmas

colincalnan's picture

If anyone has any specific theming dilemmas that they'd like solved or help with solving please post them there or message me and I'll do my best to try to include the path to the solution in my talk.

Col.

Hi Colin : Message from Drupal Enthusiastic

gohiljl_drupal's picture

Hi Colin,

I have been working in PHP since last 5 years. I have worked on Zend framework for 1.5 years, also worked on cakePHP, typo3 extensions, Now I have started learning Druapl, am willing to get expertise in theming and module customization.

I have read and learnt basic theoritical knowledge of necessary things for drupal theming.
Can you please provide some good code snippets or tutorials , so i can get actual exposure of theming
or some good code examples for theming ?

Thanks and Regards,
Jitendra Gohil .. A drupal Enthusiastic.

about Drupal theming

katy5289's picture

Hi Jitendra,

Thank you for your comment. You are welcome to join us on April 14th for our Surrey Drupal Meetup. Colin will be speaking on how to create Drupal themes using template.php. This is the PHP script that powers Drupal themes. Please RSVP here: http://www.meetup.com/surrey-drupal/events/16607568/

On Drupal.org, you can find many free themes and you can see how they are made. Drupal.org has a handbook with documentation on how to build Drupal themes: http://drupal.org/documentation/theme

I hope this will help you to get started. You are welcome to post your questions here. I'm sure others will find it helpful.

Katy,
Organizer for Surrey Drupal Meetup
www.seascapewebdesign.com

Some Theming Dilemmas

katy5289's picture

Hi Colin,

  1. I would like to know how to remove the Add Your Comment link from teasers in Drupal.

  2. Also, Parm from Surrey Drupal Meetup has questions about building better Breadcrumbs. He is trying out Menu Trails module. but when you have content produced by Views, how do you make a good breadcrumb trail?

Thanks,

Katy :-)

Also, Parm from Surrey Drupal

end user's picture

Also, Parm from Surrey Drupal Meetup has questions about building better Breadcrumbs. He is trying out Menu Trails module. but when you have content produced by Views, how do you make a good breadcrumb trail?

I just use a snippet I found here years ago in my template file that prints the breadcrumbs from the url path. So far its worked with D6 and I'm pretty sure with Views also. I found it here I believe http://drupal.org/node/93500

function get_crumb($lvl) {
    $uri_request_id = $_SERVER['REQUEST_URI'];
    $urlexplode = explode("?", $uri_request_id);
    $url = explode("/",$urlexplode[0]);

    if($url[$lvl]){
      if($lvl > 1) {
        $var = array_keys($url);
        foreach($var as $vars){
          if($vars == 1){
            $urlpathpeice .= $url[$vars];
          }
          if($vars <= $lvl && $vars > 1){
            $urlpathpeice .= '/'.$url[$vars];
          }
        }
        $urlpathalias = $urlpathpeice;
      } elseif ($lvl == 1) {
        $urlpathalias = $url[$lvl];
      }
      $urlsystem = drupal_lookup_path('source', $urlpathalias);
      $urlsystemexplode = explode("/", $urlsystem);
      $urltype = $urlsystemexplode[0];

      if($urltype == "taxonomy"){
        $term = taxonomy_get_term($urlsystemexplode[2]);
        if($url[$lvl+1]){
          return  ' &raquo; <a href="/'.$urlpathalias.'" title="'.$term->name.'">'.$term->name.'</a>';
        } else {
          return  ' &raquo; '.$term->name.'';
        }
      } elseif($urltype == "node"){
        $node = node_load($urlsystemexplode[1]);
        if($url[$lvl+1]){
          return  ' &raquo; <a href="/'.$urlpathalias.'" title="'.$nodename.'">'.$node->title.'</a>';
        } else {
          return  ' &raquo; '.$node->title;
        }
      } else {
        $urltitleexplode = explode("-", $url[$lvl]);
        $words = array_keys($urltitleexplode);
        foreach($words as $word){
          $urltitle .= ''.ucwords($urltitleexplode[$word]).' ';
        }

        // Removes trailing whitespace
        $urltitle = trim($urltitle);
        if($url[$lvl+1]) {
          return  ' &raquo; <a href="/'.$urlpathalias.'" title="'.$urltitle.'">'.$urltitle.'</a>';
        } else {
          return  ' &raquo; '.$urltitle.'';
        }
      }
    }
}

function get_crumb_all() {
    $uri_request_id = $_SERVER['REQUEST_URI'];
    $urlexplode = explode("?", $uri_request_id);
    $url = explode("/",$urlexplode[0]);

    $numbs = array_keys($url);
    foreach($numbs as $numb) {
      $crumbs .= get_crumb($numb);
    }
    return $crumbs;
}

function url_breadcrumbs() {
  $output .= '<div class="breadcrumb">';
  $output .= '<a href="/" title="Home">Home</a>';
  $output .= get_crumb_all();
  $output .= '</div>';

    return $output;
}

Then in my page.tpl.php file I use

<?php print url_breadcrumb(); ?>

Thanks for the code

katy5289's picture

Thanks for the code snippet.

I also heard about a Custom Breadcrumbs module by Jeff Eaton. http://drupal.org/project/custom_breadcrumbs
I haven't tried it out myself.

Katy :-)
Vancouver Drupal Websites

Theming Dilemmas

colincalnan's picture

Katy,

  1. I'd be happy to go through adding and removing links in theming. Can you be a little more specific about where the teaser you want to theme is displaying, in views, on the front page?

  2. The two modules I use for building breadcrumbs are Menu Breadcrumb (http://drupal.org/project/menu_breadcrumb) and Custom Breadcrumbs (http://drupal.org/project/custom_breadcrumbs). I also use theme_breadcrumb() a lot - http://drupalcontrib.org/api/drupal/drupal--includes--theme.inc/function...

I'll definitely make a note to cover these two issues at the talk.

Col.

removing "Add Comment" link from blog teasers

katy5289's picture

Hi Colin,

I set up a custom blog with Drupal and made a view to display the blog teasers. You can see it here: http://seascapewebdesign.com/blog. It doesn't make sense to me to have "Add Comment" link on the teaser so I'd like the option of removing it. I think "Add Comment" link should go at the end of the blog post. What do other people think?

Katy :-)

It's in the view

colincalnan's picture

Katy,

the "Add Comment" link appears if there are no comments. If there are comments on the post it will show "X Comments" and link to the comments at the bottom of the post. So you have to ask yourself if you want to show that link, even if there are no comments. If you want to turn that link off, it's a simple checkbox in views. To turn those off:

  1. Edit your view
  2. In Basic Settings, click on the gear icon next to "Row style: Node"
  3. In the options that appear, uncheck the box "Display links". That will get rid of the "Add Comment" and any other node links.

Anyone driving from Vancouver to this?

malcolm8's picture

Would love to hitch a ride. I'm happy to contribute gas money.

Cheers!

Malcolm

Hansel

mackh's picture

http://drupal.org/project/hansel

is also really sweet

Drupal 6

colincalnan's picture

Hi, a quick update.

I will be talking about Drupal 6 theming specifically and not covering the new Drupal 7 theming API.

Thanks for coming out

colincalnan's picture

Thank you to all who attended last night, it was a great meetup and I hope you got as much from the talk as I did.

Here's a link to some of the notes from the things we went through, I hope they are helpful. Again if you need any help or have any further questions please don't hesitate to contact me.

https://docs.google.com/present/view?id=d353v8w_11gk9577c5