I hardly managed it to create theme hook suggestions to work with different bean blocks, so I can use custom .tpl files like:

bean--{bundle_name}.tpl.php // currently only bunde is 'zielgruppe'

Here is the code so far:

 * Override or insert variables into the block templates.
function mymodule_preprocess_block(&$variables) {
  // For bean blocks.
  if ($variables['block']->module == 'bean') {
    // Get the bean elements.
    $beans = $variables['elements']['bean'];
    // There is only 1 bean per block.
    $bean = $beans[reset(element_children($beans))];
    // Add bean type classes to the parent block.
    $variables['classes_array'][] = drupal_html_class('bean-' . $bean['#bundle']);
    // Add template suggestions for bean types.
    $variables['theme_hook_suggestions'][] = 'bean__' . $bean['#bundle'] . '_tile';
    $variables['theme_hook_suggestions'][] = 'bean__' . $bean['#bundle'] . '_' . $bean['#entity']->delta;

But for the last suggestion I just cant figure how to freakin name the file. delta prints "für-angehende-lehrkräfte". I've tried to following file names which dont get noticed:


(appearently stack messes up ü characters in code areas)

For instance, bean--zielgruppe-tile.tpl.php works.

  • 2
    You have non-ascii characters in machine names? You shouldn't. Can't you change delta to 'fur-angehende-lehrkraft' or something? It's not displayed to users after all.
    – Mołot
    Feb 13, 2014 at 12:08
  • well i guess thats the problem, using ->bid works fine. thanks :)
    – Alex
    Feb 13, 2014 at 12:09
  • the weird thing is that drupal_html_class would not make this better... is there another wrapper/function to make such strings ascii-only?
    – Alex
    Feb 13, 2014 at 12:10
  • 1
    but I have no idea about using bid and stuff, all I could post would trigger low quality filter right away '-
    – Mołot
    Feb 13, 2014 at 12:20
  • 1
    Double check the database ans make sure that it can store these non-ascii characters. Drupal likes to store all kinds of things in the database.
    – Hoytman
    May 30, 2014 at 13:05

2 Answers 2


It appears that you have non-ASCII characters in your machine names. That is not a good idea, because they are used in file system constructs and your file system's character set encoding for non-ASCII characters is not necessarily the same as Drupal's internal character set encoding (UTF-8). Since the machine names are never displayed to users, the simple workaround is to only use ASCII characters in machine names.

Just replace the non-ASCII characters in your machine names with ASCII near equivalent characters (ü → u and so on), and you will not have to guess how to create file names matching your machine names.

PS: Note that this answer is just an expansion on the upvoted comment made by Mołot on Feb 13th. I think a full answer may help future readers. However, I'll delete it if the OP posts a self-answer or if Mołot prefer to expand the comment into a full answer himself.

  • youre not getting an upvote since, as you said, molot already answered it but for some reason did not post an answer, so here you go. thanks!
    – Alex
    Feb 18, 2014 at 15:44

You can also output the theme_hook_suggestion with DSM. You'll see all the suggestions and template candidates for your content. (https://drupal.org/project/devel_themer could help you too)

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.