Can anyone, please, provide an example on how to use the theme_content_exclude function in my template.php file to exclude some fields from the $content array?
I know it must be easy but my php skills are limited.

This is what I'm talking about:
http://drupal.org/node/300368

Comments

phreestilr’s picture

Any luck on this? I'm trying to use it as well and cannot get it to work

phreestilr’s picture

Well, figured it out. It was much simpler than I thought, but there seemed to be some misleading help on the web. For anyone looking to exclude fields from $content, just copy the theme_content_exclude function from content.module to your template.php file, change 'theme' to your theme, add adjust the code to suit your needs. It should look something like:

function THEME_content_exclude($content, $object, $context) {	
  // The field may be missing info for $contexts added by modules
  // enabled after the field was last edited.
  if (empty($object['display_settings'])
    || empty($object['display_settings'][$context])
    || !is_array($object['display_settings'][$context])
    || empty($object['display_settings'][$context]['exclude'])) {
    return FALSE;
  }
  else {
    return TRUE;
  }
}

I still have one question, though. Is there any way to find out which node the current field is a part of? I would like to load the node, find out the node creator, etc

Thanks!

phreestilr’s picture

Priority: Minor » Normal
phreestilr’s picture

Version: 6.x-2.1 » 6.x-3.x-dev
gg4’s picture

@phreestilr or anyone else. An example would be very helpful.

markus_petrux’s picture

Status: Active » Fixed

Re: "Is there any way to find out which node the current field is a part of?"

Not within this context where this function is executed.

You need to explore alternative approaches, for example, you can inject your own #pre_render callback to the node content structure (look at content_nodeapi() for an example), and here you'll find all the data related to the node, and you can exclude whatever you may need.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.