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.

dynamically change the facet block title

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;}

1 Answer 1


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(&$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

  • Thanks for the response! How can i change a specific block; not all blocks titles I use “if ($block→delta=’1’)” but it change all titles from all blocks. I managed to do this by making different .tpl files for each block but I also need to have different block titles for each page. It will be better to have only different .tpl for each page and not for each block. The best will be to call the field label each time automatically.
    – Kanast
    Commented May 8, 2017 at 15:06
  • If the block has the default no_cache or cache_per_page, you can just add the logic to the preprocess function to set the title. Check the $variables array for items to determine your block title. Commented May 8, 2017 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.