Facet block with dynamic title Is there a way to dynamically change the facet block title on each page based on the field label of the specific content type? The same field has different labels in each content type.

For example if we have in ‘Content type 1’ a field with Machine name: field_1 and label ‘AA’ and the same field in ‘Content type 2’ with label ‘BB’ when we are on Content type 1 page the facet block mast show AA and when we are on Content type 2 page it mast show BB.



I found a way to change the title with CSS using the Code per Node module, but it is not automatic and I have to insert the code in each content type. It doesn't seem to be right. There must be a better way.

I use this CSS in each content type.

.block-facetapi-”THEBLOCKID” .block-title {
  visibility: hidden;}
.block-facetapi-”THEBLOCKID” .block-title::after {
  content: 'Label B';
  visibility: visible;}
You could change the block title in your theme or module using the theme function or theme preprocess function.

For example:

/**
 * Implements hook_preprocess_facetapi_title
 */
function HOOK_preprocess_facetapi_title(&amp;$variables) {
  $some_condition = TRUE;
  // If some condition
  if ($some_condition) {
    // Some title..
    $title = t('Custom title');
    // Set theme/template variable for title
    $variables['title'] = $title;
  }
}


See also: theme_facetapi_title