Home > Drupal, Drupal Planet > how to override a specific output in drupal

how to override a specific output in drupal

Finding a hard time how to override a specific output in drupal?

well, there’s a way how to do that

for example, we will override the country field in addresses module

located in address/address.inc

here’s the function:


function theme_addresses_field_country_name($afields) {
$countries = _addresses_country_get();
return '<dt>'. t('Country') .': </dt><dd>'. $countries[$afields['country']] .'</dd>';
}

what we will do is actually we will override this throug our template.php file

we take acquai_marina for this

function acquai_marina_addresses_field_country_name($afields) {
$countries = _addresses_country_get();
return $countries[$afields['country']];
}

or

function phptemplate_addresses_field_country_name($afields) {
$countries = _addresses_country_get();
return $countries[$afields['country']];
}

There we remove the extra tags to for country field

As you can see, we replace the string/text from “theme” to “acquia_marina”/”phptemplate”.

don’t be confused about “acquia_marina” or “phptemplate”  because they behave the same.

This snippet works with hook_theme() or theme_YOURMODULE() override.

Advertisement
Categories: Drupal, Drupal Planet
  1. Ben
    October 20, 2009 at 6:42 am | #1

    It’s best to get into the habit of using the theme name rather than phptemplate in the function override as Drupal 7 will only accept theme names when overriding a function.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.