theming

Use $body_classes To Apply CSS To Specific Pages Or Sections

I love using the http://drupal.org/project/framework theme. It is a great starter theme when building from scratch. Drop the following into template.php and you can easily theme different sections of your site based on the path or section.
<?php
/**
* Intercept page template variables
*
* @param $vars
* A sequential array of variables passed to the theme function.
*/
function framework_preprocess_page(&$vars) {
if (!$vars['is_front']) {
// Add unique classes for each page and website section
$path = drupal_get_path_alias($_GET['q']);

Theming a Template in a Module


// hook_menu()
function example_menu() {

$items = array();
$items['get_user_profile'] = array(
'title' => 'User Profile',
'page callback' => 'get_user_profile',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK
);

function get_user_profile($uid, $gid){
$data = array('uid' => $uid,
'gid' => $gid,
);
return theme('user_profile_data',$data);
}

// hook_theme()
function example_theme() {
return array(
'user_profile_data'=> array(
'arguments'=> array('rows'=>NULL,),

Remove The 'Add New Comment' From Teasers

Here is a quick way to remove the 'Add new comment' link from teaser views. Put the following into your custom, site specific module.

How to Remove the Colon After Field Labels

Sometimes you need to remove the colon that is printed by default after all field labels. For instance in webforms you might be asking a question such as 'What is your favorite color?:' See how ridiculous the colon looks after the question mark?

Let's get rid of that.

Login and Register on the Same Page with Custom Error module

Code for the customerror 403 access denied page.

<?php
drupal_add_js
('misc/collapse.js');
drupal_add_js('misc/drupal.js');
?>


<div id="user_login_inner">
<div id="user_login_outer">

  <div id="user_login_msg">
    With your FREE account, you can:
    <ul>
      <li>Post articles and stories</li>
      <li>Add local area events</li>
      <li>Add a directory listing</li>
    </ul>
  </div>


  <div id="user_login_area">

    <div id="user_login_login">
      <fieldset>
        <legend><?php print t("Login"); ?></legend>
        <div class="fieldset-wrapper">
          <h2><?php print t(""); ?></h2>
          <?php print drupal_get_form('user_login'); ?>
        </div>
      </fieldset>
    </div>

    <div id="user_login_register">
      <fieldset>
        <legend><?php print t("Register"); ?></legend>
        <div class="fieldset-wrapper">
          <h2><?php print t(""); ?></h2>
          <?php print drupal_get_form('user_register'); ?>
        </div>
      </fieldset>
    </div>

  </div>

</div>
</div>

Change the size of a CCK input field

There appears to be two ways to alter the width of a cck textfield if the widget does not offer that option within its configuration settings.

1. Change it via css

#edit-field-list-phone-1-value {
  width: 100px;
}

2. Change it via a custom module

This link tells you how.

Rearrange Form Elements in template.php

I want to change the way the 'Add Page' form appears. In order to override the default page form, you'll have to register your own theme function in either a module or inside template.php.

I am going to use template.php. To get the internal name of the form, just view the html source of your 'Add Page' page and search for 'form_id'. The form_id of the form we're after is 'page_node_form'.

function garland_theme () {
  return array(
    'page_node_form' =>  array(
      'arguments' => array('form' => NULL),
    ),
  );
}

I have registered the function. Note the form_id and the fact that $form should be passed as an argument.

Now I will create the overriding function that will be called instead of the default page_node_form. My function here is not very useful. It's only intended to illustrate how to do these things. What I'm going to do is move the 'title' field below the 'body' field. And while I'm at it I will change the label above the body field to include the users fullname. Fullname is a field I included in the user profile.

function garland_page_node_form($form) {

Syndicate content

Contact Me

Feel free to contact me.

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.