页面模板未加载,但节点模板正在加载

发布于 2024-09-17 08:21:18 字数 1351 浏览 3 评论 0原文

sys 信息:drupal 6 安装,包含大量模块...太多,无法列出。

问题:只有特定的内容类型将无法正确加载其模板文件。一些将通过视图显示在这些页面上的节点正在进入标记。它们是唯一加载的内容。该内容所依赖的模板文件是node-event.tpl

目标:加载page-team.tpl.php

模板建议通过

mytheme_preprocess_page(&$vars, $hook)

_phptemplate_variables ()< 转换而来 的预处理在 template.php 中以两种方式加载/code> 在 drupal 5 安装中。

方法1:

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;
    }
  }
}

方法2:

if ($vars['node']->og_groups['0'] || preg_match('/fdl\//',$vars['node']->path) || (preg_match('/og\/manage/',$alias) || preg_match('/og\/invite/',$alias) || preg_match('/og\/users/',$alias)) || (preg_match('/node\/add/',$alias) && $_GET['gids'] != '') || $vars['node']->og_description || (arg(0) == 'user' && is_numeric(arg(1)))) { 
  $vars['template_files'][] = 'page-team';

}

page-team是缺少的tpl,我怀疑上面的代码(方法2)可能有错误。

我正在尝试为第一个路径参数为“fdl”的所有页面加载此模板,因此 site.com/fdl 以及 fdl 的所有子级。

我知道有很多可能性。但我有一种感觉,错误就在这里。感谢您提供的任何帮助。

sys info: drupal 6 installation, with tons of modules... too many to list.

the problem: only a certain content type will not load it's template file correctly. some nodes that would be displayed on these pages through views are making it to the markup. they are the only content that gets loaded. the template file that this content falls back on is node-event.tpl

the objective: to load page-team.tpl.php

template suggestions are loaded in two ways in template.php through preprocessing via

mytheme_preprocess_page(&$vars, $hook)

converted from _phptemplate_variables () in a drupal 5 installation.

method 1:

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;
    }
  }
}

method 2:

if ($vars['node']->og_groups['0'] || preg_match('/fdl\//',$vars['node']->path) || (preg_match('/og\/manage/',$alias) || preg_match('/og\/invite/',$alias) || preg_match('/og\/users/',$alias)) || (preg_match('/node\/add/',$alias) && $_GET['gids'] != '') || $vars['node']->og_description || (arg(0) == 'user' && is_numeric(arg(1)))) { 
  $vars['template_files'][] = 'page-team';

}

page-team is the tpl that is missing, and i suspect there may be an error with my code above (method 2).

i'm attempting to load this template for all pages with the first path argument of "fdl" so site.com/fdl and all children of fdl.

i know there are lots of possibilities. but i have a feeling the error is here. thanks for any help you can offer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

滥情哥ㄟ 2024-09-24 08:21:18

嗯,你清除缓存了吗?因为在处理主题时,drupal通常会在清除缓存后捕获新添加的主题和模板。

如果您不确定您的注册。 exp.,我相信你可以简单地这样写:


if(strpos(drupal_get_path_alias($_GET['q']),'fdl')===0){
    $vars['template_files'][] = 'page-team';
}

并清除缓存。

Well, did you clear cache? Because when dealing with themes, drupal usually catches newly added themes and templates after clearing cache.

And if you are not sure about your reg. exp., i believe you can simply write this:


if(strpos(drupal_get_path_alias($_GET['q']),'fdl')===0){
    $vars['template_files'][] = 'page-team';
}

And clear cache.

毁梦 2024-09-24 08:21:18

这就是我的 template.php 中的内容:


function frontend_preprocess_page(&$vars){
  if(strpos(drupal_get_path_alias($_GET['q']),'dummy_tests')===0){
      $vars['template_files'][] = 'page-dummy';
  }
}

frontend 是我的主题的名称。我在主题文件夹中有一个文件 page-dummy.tpl.php 。为了看看它是否有效,我在 body 标签后面添加了“IT WORKS”。然后清除缓存。现在我转到页面“mydomain.com/dummy_tests/1”并看到它可以工作。

如果遇到问题,请尝试检查 drupal_get_path_alias($_GET['q']) 的输出。只需


print drupal_get_path_alias($_GET['q']);

在 preprocess_page() 函数内部执行即可。如果它真的以“fdl”开头,那么一切都应该有效。这是一个有效的示例,因此您只需尝试一下并找出为什么它不适合您。

顺便说一句,尝试删除节点模板并仅保留页面模板。我不知道为什么,但可能是出了什么问题,drupal 搞乱了它们。

This is what i have in my template.php:


function frontend_preprocess_page(&$vars){
  if(strpos(drupal_get_path_alias($_GET['q']),'dummy_tests')===0){
      $vars['template_files'][] = 'page-dummy';
  }
}

frontend is the name of my theme. I have a file page-dummy.tpl.php inside the theme folder. To see that it works i added "IT WORKS" right after the body tag. Then cleared cache. Now i go to page "mydomain.com/dummy_tests/1" and see that IT WORKS.

If you are having problems, try to check the output of drupal_get_path_alias($_GET['q']). Just do


print drupal_get_path_alias($_GET['q']);

right inside the preprocess_page() function. And if it really starts with "fdl" everything should work. This is a working example, so you just try to play around and figure out why it's not working for you.

BTW, try to remove the node template and leave only the page template. I don't know why, but may be something is wrong and drupal messes them.

离笑几人歌 2024-09-24 08:21:18

我尝试在 page_preprocess 和 node_preprocess 函数中添加自定义模板。它对我来说适用于页面模板和节点模板。


function frontend_preprocess_page(&$vars){
  if(strpos(drupal_get_path_alias($_GET['q']),'dummy_tests')===0){
      $vars['template_files'][] = 'page-dummy';
  }
}

function frontend_preprocess_node(&$vars){
  if(strpos(drupal_get_path_alias($_GET['q']),'dummy_tests')===0){
      $vars['template_files'][] = 'node-dummy';
  }
}

I tried adding custom templates in both page_preprocess and node_preprocess functions. And it worked both for page and node templates for me.


function frontend_preprocess_page(&$vars){
  if(strpos(drupal_get_path_alias($_GET['q']),'dummy_tests')===0){
      $vars['template_files'][] = 'page-dummy';
  }
}

function frontend_preprocess_node(&$vars){
  if(strpos(drupal_get_path_alias($_GET['q']),'dummy_tests')===0){
      $vars['template_files'][] = 'node-dummy';
  }
}

挥剑断情 2024-09-24 08:21:18

我在模板中发现了一个已弃用的链接函数。更新参数解决了一切。

i found a deprecated link function in the template. updating the parameters fixed everything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文