I need to show a block if a field has a given state, or print nothing if it has a different state. I can get it to work using a field template with the code below, but printing useless html just to stop it from rendering it's default output seems more than a little hacky.
I've tried setting $element = null;
- that didn't work. I tried changing #markup to be empty, that didn't work. Even using print '';
means Drupal kicks it's default rendering back in.
Is there a recommended method for telling a field to do nothing?
<?php if($element['#items'][0]['value'] === 1){
//This is an archive page - show the block.
$block = module_invoke('customblocks', 'block_view','archive');
print render($block['content']);
} else {
//nothing to do here - not an archive page
//The only way to stop Drupal rendering something appears to be to get it to print SOMETHING.
//So we're going to print an invisible hr.
print '<hr style="display:none;" />';
}
?>