/** * @file * The primary PHP file for this theme. */ function zimmer_preprocess_page(&$variables) { if (isset($variables['node'])) { $suggests =& $variables['theme_hook_suggestions']; $args = arg(); unset($args[0]); $type = "page__type_{$variables['node']->type}"; $suggests = array_merge($suggests, array($type), theme_get_suggestions($args, $type)); } }
function Boson_preprocess_page(&$vars) { // Do we have a node? if (isset($vars['node'])) { // Ref suggestions cuz it's stupid long. $suggests =& $vars['theme_hook_suggestions']; // Get path arguments. $args = arg(); // Remove first argument of "node". unset($args[0]); // Set type. $type = "page__type_{$vars['node']->type}"; // Bring it all together. $suggests = array_merge($suggests, array($type), theme_get_suggestions($args, $type)); echo '<pre>'; print_r($suggests); echo '</pre>'; // if the url is: 'http://domain.com/node/123/edit' // and node type is 'blog'.. // // This will be the suggestions: // // - page__node // - page__node__% // - page__node__123 // - page__node__edit // - page__type_blog // - page__type_blog__% // - page__type_blog__123 // - page__type_blog__edit // // Which connects to these templates: // // - page--node.tpl.php // - page--node--%.tpl.php // - page--node--123.tpl.php // - page--node--edit.tpl.php // - page--type-blog.tpl.php << this is what you want. // - page--type-blog--%.tpl.php // - page--type-blog--123.tpl.php // - page--type-blog--edit.tpl.php // // Latter items take precedence. } }
function corporateclean_preprocess_page(&$vars) { if (isset($vars['node'])) { // Ref suggestions cuz it's stupid long. $suggests =& $vars['theme_hook_suggestions']; // Get path arguments. $args = arg(); // Remove first argument of "node". unset($args[0]); // Set type. $type = "page__{$vars['node']->type}"; // Bring it all together. $suggests = array_merge($suggests, array($type), theme_get_suggestions($args, $type)); } if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) { $term = taxonomy_term_load(arg(2)); $vars['theme_hook_suggestions'][] = 'page__vocabulary__' . $term->vocabulary_machine_name; } }
/** * Ensure page-front template suggestion is added when on front page. */ function testFrontPageThemeSuggestion() { // Set the current route to user.login because theme_get_suggestions() will // query it to see if we are on the front page. $request = Request::create('/user/login'); $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'user.login'); $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/user/login')); \Drupal::requestStack()->push($request); $this->config('system.site')->set('page.front', 'user/login')->save(); $suggestions = theme_get_suggestions(array('user', 'login'), 'page'); // Set it back to not annoy the batch runner. \Drupal::requestStack()->pop(); $this->assertTrue(in_array('page__front', $suggestions), 'Front page template was suggested.'); }
/** * Ensure page-front template suggestion is added when on front page. */ function testFrontPageThemeSuggestion() { $original_path = _current_path(); // Set the current path to node because theme_get_suggestions() will query // it to see if we are on the front page. \Drupal::config('system.site')->set('page.front', 'node')->save(); _current_path('node'); $suggestions = theme_get_suggestions(array('node'), 'page'); // Set it back to not annoy the batch runner. _current_path($original_path); $this->assertTrue(in_array('page__front', $suggestions), 'Front page template was suggested.'); }
/** * Variables preprocess function for the "page" theming hook. */ function may_bragdon_theme_preprocess_page(&$vars) { $current_path = current_path(); $url_parts = explode('/', $current_path); $last_part = null; if (sizeof($url_parts) > 0) { $last_part = $url_parts[sizeof($url_parts) - 1]; } // Do we have a node? if (isset($vars['node'])) { // Ref suggestions. $suggests =& $vars['theme_hook_suggestions']; // Get path arguments. $args = arg(); // Remove first argument of "node". unset($args[0]); // Set type. $type = "page__type_{$vars['node']->type}"; // Bring it all together. $suggests = array_merge($suggests, array($type), theme_get_suggestions($args, $type)); // if the url is: 'http://domain.com/node/123/edit' // and node type is 'blog'.. // // This will be the suggestions: // // - page__node // - page__node__% // - page__node__123 // - page__node__edit // - page__type_blog // - page__type_blog__% // - page__type_blog__123 // - page__type_blog__edit // // Which connects to these templates: // // - page--node.tpl.php // - page--node--%.tpl.php // - page--node--123.tpl.php // - page--node--edit.tpl.php // - page--type-blog.tpl.php // - page--type-blog--%.tpl.php // - page--type-blog--123.tpl.php // - page--type-blog--edit.tpl.php // // Latter items take precedence. } else { if ($last_part == 'pages') { // Ref suggestions. $suggests =& $vars['theme_hook_suggestions']; // Get path arguments. $args = arg(); // Remove first argument of "node". unset($args[0]); // Set type. $type = "page__type_pages"; // Bring it all together. $suggests = array_merge($suggests, array($type), theme_get_suggestions($args, $type)); } else { if (isset($vars['page']['content']['system_main']['islandora_book'])) { // Ref suggestions. $suggests =& $vars['theme_hook_suggestions']; // Get path arguments. $args = arg(); // Remove first argument of "node". unset($args[0]); // Set type. $type = "page__type_diary"; // Bring it all together. $suggests = array_merge($suggests, array($type), theme_get_suggestions($args, $type)); } else { if (isset($vars['page']['sidebar_second']['islandora_compound_object_compound_navigation'])) { // Ref suggestions. $suggests =& $vars['theme_hook_suggestions']; // Get path arguments. $args = arg(); // Remove first argument of "node". unset($args[0]); // Set type. $type = "page__type_inclusion"; // Bring it all together. $suggests = array_merge($suggests, array($type), theme_get_suggestions($args, $type)); } else { //dpm("don't know"); } } } } }