I have a Drupal filter module whose output I would like to alter, depending on where the output is going to be displayed. Specifically, I want to the filter to give the full output for nodes, but trim the content down for blocks.
How to change Drupal input filter behaviour based on output location
267 views Asked by Tim At
2
There are 2 answers
1
On
I'm the OP (but just registered an account).
I did manage to find a solution/workaround. Here's what I did:
- Create block.tpl.php in my module which is a copy from system/block.tpl.php, with a constant added at the top.
- Put my template file at the head of the theme registry using hook_theme_registry_alter():
function hook_theme_registry_alter(&$theme_registry) { // using our own block.tpl.php file. $theme_registry['block']['template'] = 'block'; $theme_registry['block']['path'] = drupal_get_path('module', 'module_name'); $theme_registry['block']['type'] = 'module'; $theme_registry['block']['theme path'] = drupal_get_path('module', 'module_name'); $theme_registry['block']['theme paths'] = Array(); }
- Checked for the constant while constructing the filter output, changing as necessary.
- Celebrated the outcome.
I don't think this would be possible. It's hard enough to figure out what context something is being displayed in. It's doable but quite hard to code on your own. However the way the filter system works I don't think its possible within a filter to determine then context of the text being filtered. It's simply not made for something like that.