3

I have been trying to figure out a method to override the locations.tpl.php template on a per content type basis, but I can't find any good examples on doing this with module template files rather than core template files. Is there code that could be inserted into template.php so that location--blog.tpl.php could be used in the same way that node--blog.tpl.php can be used? Interested in the location module specifically, but would appreciate pointers for general methods of theming contrib modules.

2 Answers 2

1

@

Drupal 7 Template Suggestions
http://drupal.org/node/1089656

lists template suggestions in core. It references,

Custom Template Suggestions

Custom suggestions beyond the ones listed below can be created. See the page Working with template suggestions. http://drupal.org/node/223440#custom-suggestions

which provides examples for mod'ing template.php so that "All layers from core, modules, theme engines and themes can provide the suggestions."

which may provide a start for you.

1
  • These pages are both for making page and node templates, I am looking more for some steps to override module templates in a similar way.
    – sarahjean
    Jul 11, 2011 at 14:31
1

You could use the following function.

Paste it in your theme file template.php

function MY_THEME_NAME_preprocess_location(&$variables) {
    $query = db_select('location_instance', 'n');
    $nid_field = $query->addField('n', 'nid');
    $query->condition('lid', $variables['location']['lid']);
    $result = $query->execute();
    foreach($result as $n){
        $node = node_load($n->nid);
        $variables['theme_hook_suggestions'][] = 'location__node__' . $node->type;      
        $variables['theme_hook_suggestions'][] = 'location__node_' . $n->nid;       
    }
}

Your theme can now detect different templates for the locations original template using this pattern: location--node--[type|nodeid].tpl.php

For instance, these would be valid template suggestions:

location--node--1.tpl.php
location--node--blog.tpl.php
1
  • do this code could work for a D6 website ?
    – user8753
    May 31, 2018 at 9:44

Your Answer

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

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