Drupal 6:Drupal Themer 为不同类型的内容类型提供相同的候选名称

发布于 2024-09-04 01:11:55 字数 423 浏览 0 评论 0原文

我是一个 drupal 新手...

我有不同类型的内容,如新闻、活动等,它们的内容是不同的。新闻详细信息页面有标题-内容文本-日期。但活动详细信息页面有标题-日期-内容文本-位置-演讲者等。所以我需要针对这些不同类型的不同布局页面。因此,我启用了 Drupal Themer 来获取候选名称。对于事件页面,它给了我 page-node.tpl.php ,它也为新闻页面提供了相同的信息:(我如何分离这些页面?我期望像 page-event- node.tpl ,但没有...:/ Drupal Themer 还为事件页面提供了唯一的候选名称,例如 page-node-18.tpl.php 但这并不意味着任何事情,因为我可以不通过此节点名称创建所有事件的总体布局:(

感谢帮助很大!!非常感谢!!!

I'm a drupal newbie...

I have different type of contents like News, Events, etc. and their content is different. News detail page has title-content text-date. but Events detail page has title-date-content text-location-speaker-etc. So I need different layout page for these different types. So, I enabled Drupal Themer to get a candidate name. for events page, it gave me page-node.tpl.php and it gives same for News page as well :( how can I separate these pages? I expected sth like page-event-node.tpl , but no... :/ Drupal Themer also give unique candidate name for event page like page-node-18.tpl.php but it doesnt mean anything since I can not create a general layout for all events by this node name. :(

Appreciate helps so much!! Thanks a lot!!!

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

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

发布评论

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

评论(2

强辩 2024-09-11 01:11:55

虽然按照 Monkeyninja (+1) 建议使用不同的 node.tpl.php 文件是“正常”方式,但您可以通过自己根据节点类型添加页面模板建议来添加所需的功能,在 preprocess_page function 在自定义模块/主题中:

function yourModuleOrTheme_preprocess_page(&$variables) {
  // If this is a node page, add a page template suggestion based on node type
  if (isset($variables['node'])) {
    // Build the suggestion name ('.tpl.php' suffix will be added by the theming system)
    $suggestion = 'page-type-' . $variables['node']->type;
    // Add to end of suggestion array, thus keeping the fallback to other suggestions,
    // if this specific version is not implemented by the theme
    $variables['template_files'][] = $suggestion;
  }
} 

有了这个,您应该能够添加例如“page-type-event.tpl.php”文件,该文件应用于所有事件节点页面。

(注意:添加后,您需要触发主题注册表的重建函数使其被系统识别)

While using different node.tpl.php files as suggested by monkeyninja (+1) would be the 'normal' way, you could add the functionality you want by adding page template suggestions based on node type yourself, in a preprocess_page function within a custom module/theme:

function yourModuleOrTheme_preprocess_page(&$variables) {
  // If this is a node page, add a page template suggestion based on node type
  if (isset($variables['node'])) {
    // Build the suggestion name ('.tpl.php' suffix will be added by the theming system)
    $suggestion = 'page-type-' . $variables['node']->type;
    // Add to end of suggestion array, thus keeping the fallback to other suggestions,
    // if this specific version is not implemented by the theme
    $variables['template_files'][] = $suggestion;
  }
} 

With this in place, you should be able to add e.g. a 'page-type-event.tpl.php' file, which should be used for all event node pages.

(NOTE: You'll need to trigger a rebuild of the theme registry after adding that function to get it recognized by the system)

星軌x 2024-09-11 01:11:55

我不熟悉 Drupal Themer,但稍微不同的方法是使用节点模板来设计内容并使用类似优秀的 上下文模块(可能还有面板模块)来更改布局页面上的任何附加信息(例如块)。

要使用节点模板对不同的内容类型进行主题化,只需以node-content_type.tpl.php 形式基于node.tpl.php 创建模板。因此,您将拥有一个名为 node-events.tpl.php 的事件节点模板。

然后,您可以使用上下文模块定义上下文,该模块在显示事件内容类型的页面时做出反应,并选择要显示的区域/块。

I'm not familiar with Drupal Themer, but a slightly different approach would be to work with the node templates to style the content and use something like the excellent Context module (and possibly Panels module) to change the layout of any additional information on the page (eg the blocks).

To theme the different content types using node templates, just create templates based on node.tpl.php in the form node-content_type.tpl.php. So you'd have a template for your events nodes called node-events.tpl.php.

You could then define a context using the Context module that reacted when a page of the events content type was displayed and select which regions/blocks you wanted displayed.

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