Trent Wyman


PHP Scripts

The script below is an example of how to embed a view into a node template (.tpl file) in Drupal.

<?php
/* Invoke the views module and assign to a variable */
$myVar = module_invoke('views', 'block' , 'view', 'my-block_id...

To increase the default php memory limit and max file upload size in Drupal 6, the following methods can be performed:

If you have access to your php.ini file add this script (recommended):

In your php.ini file...

The following PHP function checks to see if a particular taxonomy id (term name) exists:

<?php
if(!empty($node->taxonomy) && $node->taxonomy[6]-->name == 'Term-name-here'){
print 'Term exists';
}else{...

The following PHP script checks to see if a url argument is TRUE:

<?php
if($_SERVER["REQUEST_URI"] == '/contact'){
print 'Contact';
}else{
print '';
}
?>

Here is a list of available variables within page.tpl for Drupal 6:

General utility variables:
$base_path: The base URL path of the Drupal installation. At the very least, this will always default to /.
$css: An array...

The following PHP script can be used to check if the Drupal home page is TRUE:

<?php
if($is_front){
print 'This is the front page';
else{
print 'This is an interior page';
}
?>

Basic PHP date() script:

<?php print date('Y'); ?>

--------------------------------------------------------

Simple copyright statement using year ('Y') date format:

<?php echo...

Here is an example of applying a Drupal Imagecache preset to the output of an imagefield within a .tpl file.

Example:

<?php print theme('imagecache', 'preset_name_here',$node->field_my_image[0]['filepath']);?>

Here is a Drupal PHP example using !empty that checks to see if a particular field has content. If the field IS NOT empty, then display the contents of that field. Else, output a text string.

Example:

<?php
// Setup a...

Announcements

DrupalCon Denver 2012 - I'm Going!

Press Release:
Michael C. Carlos Museum

Read the press release announcing the Drupal redesign of Emory University's Michael C. Carlos Museum. View Press Release