Showing posts with label Theming. Show all posts
Showing posts with label Theming. Show all posts

Tuesday, August 24, 2010

Day 1 - DrupalCON CPH - Lessons/tips...

The following are the most important Drupal-related modules that were mentioned/debated at Day One of the Drupal Con CPH 2010:

The Modules
- Panels (Project-Panels)
- Display Suite (Project-DS)
- Data (Project-Data)
- Composite Layout for nodes (Project-Composite)

The Starter themes
- Zen
- BluePrint (Works with the BluePrint CSS library)
- Foundation  (comment was that it was in many ways FAR superior to Zen) 

Tuesday, June 29, 2010

Checking whether a user has a specific role...

Drupal 6 makes it easy to check whether or not a user has a specific Access Privilege.  It is indeed used in most modules, as it is essential and yields much power and flexibility in use.

What Drupal 6 does however NOT make trivial, is to check whether or not a user has specific role ( a named role, e.g. "administrator", "authenticated", "member" - whatever roles you may use).
How-to
<?php  global $user;

 
// Check to see if $user has the administrator role.
 
if (in_array('administrator', array_values($user->roles))) {
   
// Do something.
 
}?>

Here we use the default full array that each user has as an attribute - the collected roles of the user!  Note that this array is keyed, and the role names (not unique!) are thus kept in the values of the keyed array!
Why is this useful?
Well, let's suppose that you have a list of nodes (a blog-style for example), and these nodes in the listing are authored by different users - different users with different roles indeed!  Using the technique above, will enable you to theme the blog-entries of each user-role, making it easier to visually tell them apart on-page for the reader of the blog.

Monday, June 7, 2010

Theming the "not-so-apparent" parts of Drupal content

An excerpt from the above-linked article/resource:
"You can create theme hooks for modules you did not write
When I wanted to theme the comments form the first thing I did was looking at comment.module. There I found a call like this:

drupal_get_form('comment_form', $edit, $title) 


Ok, I had a comment_form function that I could theme according to Drupal Form API, then I started looking for theme_comment_form but there was none.
How to override a theme hook that does not exist? Just as you do with your own modules, you just need to know the code involved and, this is important, you can include a hook_theme function in your template.php file. This is what I did for Woodpig:

function woodpig_theme() {
return array(
'comment_form' => array(
'arguments' => array('form' => array()),
),
);


The function starts with the theme name and the theme hook takes the form argument because it's a that's what drupal_get_form requires. Then I can write my own woodpig_comment_form($form) function."

Wednesday, June 2, 2010

Node: Body outputs entire full node, instead of Body field

The problem is not, as the linked article here suggests, limited to Views representations of Node-body content.  The problem exists in any Node or Page template that is rendered to your website.

The problem arises from the fact that templating BOTH loads a Node, and then runs the "node-alter" routine on it - affecting the Node Body field specifically, to also include contents of CCK fields in that Node.

The problem-code
The problem arises when using this variable-call in a page-template (*.tpl.php) file:
print $node->body;
The solution-code
The solution is to replace the code above with this code instead:
print $node->content['body']['#value'];

Sunday, May 30, 2010

SimpleMenu and Devel Themer Conflict...

These two modules, which separately are awesome tools, conflict with each other...

I haven't found documentation of the specific conflict, or the reason why they conflict -But they do.

Activating the Devel Themer module, immediately disables the display of the SimpleMenu, so re-enabling the display of the SimpleMenu is a matter of visiting the relative URL "?q=admin/build/modules" - locating Devel Themer module, and disabling it.

Please contribute with comments, and especially solutions found for this :0)

Themes per content-type, and not only per node ID

This addresses the issue of ONLY having the possibility of theming nodes per node-ID, e.g:
"page-node-101.tpl-php"

In order to overcome this, and provide theming for each content-type (Defaults are of course "page", "story" in Drupal 6) that you may have created using CCK, you should look to modifying the code of the "theme_preprocess_page" function in your main "template.php"-file of your chosen theme.

Code to include in theme_preprocess_page
Here is the code to include...

// Add per content type pages
if (isset($vars['node'])) {
// Add template naming suggestion. It should alway use hyphens.
// If node type is "custom_news", it will pickup "page-custom-news.tpl.php".
if($vars['node']) $prefixName="page-node-";
else $prefixName="page-";
$vars['template_files'][] = $prefixName. str_replace('_', '-', $vars['node']->type);
}

And, as you will see, it gives you access to using two new template-names for your content-type:
- For views etc. node-listings: page-CONTENTTYPE.tpl.php
- For node-details views: page-node-CONTENTTYPE.tpl.php

Saturday, May 22, 2010

Developer modules

Just like you will need the essential modules, as the previous post outlines - then you, as the developer and designer of a Drupal website, will also benefit greatly from these...
  1. Devel Module+Devel Themer - Visualize content data, which template (theme) files that apply to a certain page or content-view, and use it to modify your pages and content!
  2. SimpleMenu* - Provide a general menu, always displayed at the top of your website - No need to reserve a block-position for this menu - it does it all!
  3. Zen-theme - A fasttrack to theming as you can literally "point-n-click" to create your own theme, and THEN specialize this theme to your liking
* SimpleMenu is great, but it has a conflict with the Devel Themer module (specifically the Themer module!), so use it with care, and when using for the admin-user you can switch Devel Themer on and off in your Modules Control Panel on your website.

Developer documentation and examples...

The general Drupal API can be found at api.drupal.org

In addition to this, you will also benefit from some select free screencasts - These display real-world usage of Drupal and Modules to provide certain custom page and content views. I can personally recommend these two...
  • Drupal Videos
  • Drupal School
Both of the above are accessible through iTunes and the iTunes Store...

Additionally, you might also like to have a copy of one or all of the Drupal Cheat Sheets lying around - It tells you all about the default variables, such as the login-status of your visiting user, and such essentials...