URL Based Drupal 7 Template Files

If I have a page with the url alias "/ api / user / create", how can I name the template file based on the URL, for example "page-api-user-create.tpl.php".

+4
source share
2 answers

You need to call it:

page--api--user--create.tpl.php 

(note the double dashes in the file name).

See http://drupal.org/node/1089656 for more details.

+4
source

You can customize the page-level template file to reflect the URL, as Maciej Zhgazdai explained.

To do the same with the node level template file, you must add it to the template.php file:

 function YOURTHEME_preprocess_node(&$variables) { $url = str_replace("-", "", $variables['node_url']); $urlParts = explode("/", $url); unset($urlParts[0]); if($urlParts[1] !== false) { $out = array(); $sug = "node"; foreach($urlParts as $val) { $sug .= "__".$val; $out[] = $sug; } $variables['theme_hook_suggestions'] = array_merge($variables['theme_hook_suggestions'], $out); } } 

Replace YOUR TOPIC. Check out the offers with devel_themer.

0
source

All Articles