views:

924

answers:

1

I need to include a node content in another node using some kind of placeholder, for example: [node-5663] will be translated to the node's content (body) where node-id matches 5663.

The example above is just an example, what I would need is actually something like this: [table-TABLE-ID] where TABLE-ID will be a field I define in the node (using CCK).

I don't have any problem searching and matching the content I need to fetch, but what I am missing is how to use the tokens.

Any help would be welcome :)

+2  A: 

While I'm a little fuzzy on the exact details of what you want, the basic premise is actually quite simple.

You will want to build a custom module, which simply defines some tokens, similar to the following:

/**
 * Implements hook_theme().
 */
function my_module_theme() {
  return array(
    'my_module' => array(
      'arguments' => array('object' => NULL)
    ),
  );
}

/**
 * Implements hook_token_list().
 */
function my_module_token_list($type = 'all') {
  if ($type == 'node' || $type == 'all') {
    $tokens = array();
    $tokens['my_module']['table-TABLE-ID'] = t('description').
    return $tokens;
  }
}

/**
 * Implements hook_token_values().
 */
function my_module_token_values($type, $object = NULL) {
  if ($type == 'node') {
    ($table, $id) = explode('-', $object->my_field['value']);
    $tokens['table-' . $object->my_field['value']] = theme('my_module', db_fetch_object(db_query("SELECT * FROM {" . $table . "} WHERE id = %d", $id)));
    return $tokens;
  }
}

function theme_my_module($object) {
  return '<div>' . $object->content . '</div>';
}

Note: All this code is theoretical and I can pretty much state that it will not work. It is also highly insecure to do the db_query the way I have done it here (which was my interpretation of what you wanted), instead you should have a token for each different type of query you want ('table-node-ID', etc).

Hope this is somewhat helpful.

Decipher
As a side note, if the token itself where to be placed the Body field you would also need the Token Filter module (http://drupal.org/project/token_filter) to translate the token.
Decipher
Excellent, Thanks :)
Eli