To implement a system to replace custom tokens, you have two possibilities, supposing that you are referring to text present in the node body that needs to be replaced with dynamic values:
- use a filter module that allows you to define which text needs to be replaced, and with what
- use a custom module that replaces the text found in the node body before the node is shown
In the first case, the filter module would be invoked also for comments, and the filter would not be able to make a difference between replacing text in a node body, or in a comment body. In the case the module allows you to define the PHP code executed when a specific text is found in the node/comment body, there is also a performance issue. Instead of passing PHP code to eval()
, it would be better to define a custom module that implements a specific filter to replace a specific text you need. Also in this case, the module would not be able to know when it is invoked for a node or a comment; it also means the filter module could not get information outside the arguments given to the filter callback, which means it is not able to get information about the author of the node, since the filter callback doesn't get any node or comment object.
In the case of Custom filter, the description given for the input format is not translatable; that means that passing from English to French as language for the site (or the node being shown), the description reported would not be shown in French.
In the latter case, a module implementing hook_nodeapi('view'), in Drupal 6, could alter the content of $node->content
to alter the node body; similarly, a module implementing hook_node_view() would achieve the same result in Drupal 7 and later versions.
In both the cases, $node->content['body']
contains the node body as array that follows the format used by the form API, or required by drupal_render().
Enabling the PHP input format for a site that is not used as developing/testing site is not considered a good idea. Rather than enabling that input format is better to implement a custom module, which is what has been done on Drupal.org that replaced a content type using the PHP input format with a normal content type, and implemented a custom module to alter the content of specific nodes.