I am using D7. I have declared a custom template facet-item.tpl.php
in a module named dsfacet
. My code goes as follows:
/**
* Implements hook_theme().
*/
function dsfacet_theme($existing, $type, $theme, $path) {
return array(
'facet_item' => array(
'variables' => array('facet_name' => NULL, 'facet_values' => array()),
'template' => 'facet-item',
),
);
}
This custom template is invoked from another template with the following code:
<?php foreach ($facets as $name => $values): ?>
<?php print theme('facet_item', array('facet_name' => $name, 'facet_values' => $values)); ?>
<?php endforeach; ?>
Everything works great so far, but I'd like my theme to use more specialized templates based on the facet name.
So here's what I did:
1) I declared a template suggestion based on the facet name:
/**
* Implements template_preprocess_HOOK for facet-item.tpl.php.
* Adds template suggestions.
*/
function template_preprocess_facet_item(&$variables) {
$variables['theme_hook_suggestions'][] = 'facet_item__' . $variables['facet_name'];
}
2) I changed the theme invocation to take into account the facet name:
<?php print theme('facet_item__' . $name, array('facet_name' => $name, 'facet_values' => $values, 'node' => $node)); ?>
3) I created some templates based on facet names:
facet-item--address.tpl.php
facet-item--phone.tpl.php
...
I then cleared the cache but... nothing happens. Only the main template facet-item.tpl.php
is used. After a few hours spent on this, I'm at my wit's end. Any ideas?
(I've tried hard-coding the facet name everywhere to make sure it wasn't a problem with my variables... I've also tried every possible permutation of singe/double dashes/underscores...)