0

I have a page with a url alias of say /food/tacos

I have created html--food--tacos.tpl.php to include some javascript only on that page. I've used this method many times (on other sites) with no problems, but Drupal (7) doesn't seem to be picking it up this time.

I have cleared all caches.

Theme debug offers the following suggestions, none of which seem to recognize the path alias. I would prefer to use the alias as I may use this theme in multiple places where the node number would not be the same.

<!-- THEME DEBUG -->
<!-- CALL: theme('html') -->
<!-- FILE NAME SUGGESTIONS:
   * html--node--3.tpl.php
   * html--node--%.tpl.php
   * html--node.tpl.php
   x html.tpl.php
-->
<!-- BEGIN OUTPUT from 'sites/all/themes/mytheme/html.tpl.php' -->

How can I get this working with the alias?

0

You have to add a theme hook suggestion (example from here):

function THEME_preprocess_page(&$variables) {
  if (isset($variables['node']->type)) {
   // If the content type's machine name is "my_machine_name" the file
   // name will be "page--my-machine-name.tpl.php".
   $variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type;
   }
} 

Use this in code in your template.php file in the theme directory and, obviously, change it :)

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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