PHP Drupal页面模板文件基于url

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Drupal页面模板文件基于url相关的知识,希望对你有一定的参考价值。

//Drupal 5
<?php
function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
    
      // Add page template suggestions based on the aliased path.
      // For instance, if the current page has an alias of about/history/early,
      // we'll have templates of:
      // page-about-history-early.tpl.php
      // page-about-history.tpl.php
      // page-about.tpl.php
      // Whichever is found first is the one that will be used.
      if (module_exists('path')) {
        $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
        if ( $alias != $_GET['q'] && $alias == $_REQUEST['q'] ) {
          $suggestions = array();
          $template_filename = 'page';
          foreach (explode('/', $alias) as $path_part) {
            $template_filename = $template_filename . '-' . $path_part;
            $suggestions[] = $template_filename;
          }
        }
        $vars['template_files'] = $suggestions;
      }
      break;
  }
  
  return $vars;
}
?>

//Drupal 6
<?php
function phptemplate_preprocess_page(&$vars) {
  if (module_exists('path')) {
    $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
    if ($alias != $_GET['q']) {
      $template_filename = 'page';
      foreach (explode('/', $alias) as $path_part) {
        $template_filename = $template_filename . '-' . $path_part;
        $vars['template_files'][] = $template_filename;
      }
    }
  }
}
?>

以上是关于PHP Drupal页面模板文件基于url的主要内容,如果未能解决你的问题,请参考以下文章

php 基于内容类型的Drupal 8自定义页面模板(建议)(页面 - [content-type] .html.twig)

如何修改drupal搜索模板?

php Drupal 8页面的模板名称

PHP nodetype上的Drupal页面模板

PHP 根据路径别名添加Drupal页面模板建议。

PHP Drupal - 页面模板取决于节点类型