Drupal Dump

Drupal Snippets, Hacks and more....

495 posts since 2011

Custom Token and languages for titles and labels

As views and even more panels are not perfect when it comes to translations if you need to have some fixed label with translation for some view/panel. You can create custom token for it and then just translate it over translation interface. Token creation is simple, just use this guide

Microdata for voteing modules

Well the year is 2012 and you must use microdata, there is a microdata module for drupal 7, but if you are still at drupal 6 you will need to customize. I have been using vote up/down module for my ratings so I needed to change template file of the module to add this microformats to node display so I added this code at the end of widget.tpl.php

Tracing available variables in template file

I often forget this one, if you need to see what available variables are in some specific template file of any contributed module you will write this on top of the tpl file

<pre> <?php print_r(get_defined_vars());?></pre>

and will get a nice list of variables you can use.

Drupal site and how to manually put it offline

Go to phpmyadmin and start this 2 commands

put site offline
UPDATE variable SET value='s:1:"1"' WHERE name = 'site_offline'
put site online
UPDATE variable SET value='s:1:"0"' WHERE name = 'site_offline

depending what you need, if you have drush you could also do that with drush.

Node export tips and problems

Currently I am moving nodes from one domain to other, with many images and cck fields. Problem I have other then browser timing out on large files when uploded through node export module is that also on smaller files, with few nodes seems that module sometimes works and sometimes doesnt. What I realized is that if you quickly select code to paste or export file, importing breaks.

Redirect Old domain to New domain using htaccess redirect

Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Panels h1 title inline with sidebar

Currently many drupal themes like fusion have h1 title use all the width of the grid so you can't have a panel where h1 tag is just part of the grid, using content area and in the same line there is sidebar.