Node object reference

Here is an overview of the node object broken down into Drupal 7, Drupal 6 and Drupal 5.

Plain unstyled HTML output (Theme unavailable)

If your site appears as plain HTML with missing styles and/or images:

Try a view-source and see what the path to the theme CSS in the header is. Does it look correct? Sometimes this can get out of sync when migrating between sites that are almost-but-not-quite identical. Some things to check:

  1. It could be you are trying to use a theme that is not active. This can happen when you have set the default theme in settings.php but that theme has not yet been added or configured. It can also occur if you did not switch back to the default theme before an upgrade. To fix that issue, go to admin > build > themes and select the default theme (Garland in 5.x and Bluemarine in 4.7 and 4.6).
  2. Your $base_url setting (in your settings.php file) may be misconfigured. The $base_url setting is what gets prepended to all paths for extra resources, such as stylesheets, images, javascript includes and form handlers. If the browser can't find those resources on that path, then they will be missing from the rendered HTML you see in your browser.
    Example:

Using Drupal for karting club

I am using Drupal for my karting club, my-kart.org (http://www.my-kart.org/).

It meets most of my requirements as a community driven CMS (forums, blogs, image galleries, calendar etc).

Show/hide certain profile fields depending on user role or user permissions

Description
This collection of snippets allows site administrators to show or hide specific profile fields, depending on user permissions or on user roles.

Usage

  • For use in a user profile page override
  • Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the snippet into the user_profile.tpl.php file
  • Tested and works with Drupal 4.5 and 4.6
  • Change the div class name or the link text to suit.

Show content based on user permissions

User permissions are specified on the ADMINISTER --> ACCESS CONTROL page.

<?php if (user_access('administer users')): ?>
<div class="fields">CONTENT FOR ADMIN ONLY GOES HERE</div>
<?php endif; ?>

Show content based on user role.

In this example snippet, the content will only be displayed to users with the super admin role type. Change the role type, DIV etc. to change the output.

<?php if (in_array('super admin',$GLOBALS['user']->roles)): ?> 
<div class="fields">Super Administraator</div>
<?php endif; ?>

Show "Read User's Blog" on profile if user has permission to add blog entries.

Display users age based on a date-of-birth field

PLEASE NOTE! These snippets are user submitted. It is impossible to check them all, so please use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

Description

This php snippet displays the age of the user, based on a date of birth field.

Dependencies: profile.module must be installed & enabled and a custom profile date field called profile_dob must be setup. This is the DATE OF BIRTH field that is used to dynamically determine the users age.

Note: If you haven't setup your date-of-birth field yet, go to Administer › User management >Profiles and add a new DATE field. Give it the name profile_dob and fill out the rest of the options as suits.

Thanks to Pepe for improving the snippet.

Usage

  • For use in your user profile page override
  • Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the snippet into your user_profile.tpl.php file
  • Change the div class name or the message text to suit.

<?php
$year_diff = date("Y") - ($user->profile_dob{year});

Disabling a buggy module

A situation can arise where you've enabled a module through the user interface, but then because of a fatal error of some kind cannot get back to the modules administration screen to disable it (sometimes you cannot access any pages of your site at all): only the error is displayed and nothing else.

This can be resolved by executing the following query in the database (replace module_name with the name of the module you are trying to disable):

Pages

Subscribe with RSS Subscribe to RSS - Drupal 6.x