drupal

How to check if the user is logged in Drupal 6 using php

I needed this snippet of code in a block to show different links based on the user's logged in state.

  1. <?php
  2. global $user;
  3. if ($user->uid) {
  4.     print "logged in";
  5. }
  6. else if (!$user->uid) {
  7.     print "please log in";
  8. }
  9. ?>
Technology: 

Drupal6 theme single node id

Here's a code snippet for having node-[nid].tpl.php style templates.

  1. function phptemplate_preprocess_node(&$vars, $hook) {
  2.   $node = $vars['node'];
  3.   $vars['template_file'] = 'node-'. $node->nid;
  4. }
Technology: 

Display Drupal 6 Custom menu in theme

There's a small catch, you have to prepend menu- to your custom name in the actual code.
You can check the url of the menu when you're in the admin for getting the actual name, if it's easier for you.

print theme('links', menu_navigation_links('menu-custom-name'));

Technology: 

Drupal Ubercart get add to cart form

  1. $output .= drupal_get_form('uc_product_add_to_cart_form_'. $node->nid, $node);
Technology: 

How to change / remove Views2 exposed button from Drupal

Add this to your template.php file.

  1. function YOUR_THEME_NAME_preprocess_views_exposed_form(&$vars, $hook) { //this is important
  2.  
  3.   // only alter the required form based on id
  4.   if ($vars['form']['#id'] == 'views-exposed-form-where-to-buy-page-1') {
  5.  
  6.     // Change the text on the submit button
  7.     $vars['form']['submit']['#value'] = t('Search');
  8.  
  9.     // Rebuild the rendered version (submit button, rest remains unchanged)
  10.     unset($vars['form']['submit']['#printed']);
  11.     $vars['button'] = drupal_render($vars['form']['submit']);
  12.   }
  13. }
Technology: 

Drupal 6 Custom content type page theme

If you ever wondered how to change the page.tpl.php for a custom content type you've found out that by default Drupal 6 doesn't know how to do it.

It's "fixed" easily by adding the following code:

  1. /**
  2.  * Override or insert PHPTemplate variables into the templates.
  3.  */
  4. function phptemplate_preprocess_page(&$vars) {
  5.   // Add per content type pages
  6.   if (isset($vars['node'])) {
  7.     // Add template naming suggestion. It should alway use hyphens.
  8.     // If node type is "custom_news", it will pickup "page-custom-news.tpl.php".

Custom Drupal 6 frontend page

If you want to customise your frontend page in Drupal 6 copy your existing page.tpl.php into page-front.tpl.php and do the customisations there.

Technology: 

Drupal body value in views template

If you're creating a view and using a custom node type for that view and don't understand why your $body variable doesn't work to display the content of the node it's because the shortcodes aren't loaded in a view template so you must use $node->content['body']['#value']

Drupal block cloning

I'm working on a website built with drupal and I ran into pretty nasty drupal 6 limitation.
You can't clone a module / have multiple instances in a default install, so after some searching I've found this nifty drupal module called MultiBlock that allows you to do exactly that.

Subscribe to drupal