如何创建自定义页面 (Drupal 6.x)

发布于 2024-10-08 19:43:38 字数 2726 浏览 3 评论 0原文

template.php 文件中,我插入了以下代码: 我在网上找到了一个提供代码的教程,但我对如何让它工作感到困惑。

我复制了下面的代码并将其插入到主题 HTML5_basetemplate.php 中。 我复制了 page.tpl.php 文件并创建了自定义页面 - page-gallery.tpl.phppage-articles.tpl.php。我在文件中插入了一些文本,只是看到我已导航到包含更改的页面。看起来 Drupal 无法识别 gallery.tpl.php 和 page-articles.tpl.php。

在 template.php 中有以下函数:

html5_base_preprocess_page()

html5_base_preprocess_node()

html5_base_preprocess_block()

在教程中使用这些函数

phptemplate_preprocess_page()

phptemplate_preprocess_block()

phptemplate_preprocess_node( )

 function phptemplate_preprocess_page(&$vars)

{
    //code block from the Drupal handbook

    //the path module is required and must be activated
    if(module_exists('path'))
    {
        //gets the "clean" URL of the current page
        $alias = drupal_get_path_alias($_GET['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;
    }
}

function phptemplate_preprocess_node(&$vars)
{
    //default template suggestions for all nodes
    $vars['template_files'] = array();
    $vars['template_files'][] = 'node';

    //individual node being displayed
    if($vars['page'])
    {    
        $vars['template_files'][] = 'node-page';
        $vars['template_files'][] = 'node-'.$vars['node']->type.'-page';
        $vars['template_files'][] = 'node-'.$vars['node']->nid.'-page';
    }
    //multiple nodes being displayed on one page in either teaser
    //or full view
    else
    {
        //template suggestions for nodes in general
        $vars['template_files'][] = 'node-'.$vars['node']->type;
        $vars['template_files'][] = 'node-'.$vars['node']->nid;

        //template suggestions for nodes in teaser view
        //more granular control
        if($vars['teaser'])
        {
            $vars['template_files'][] = 'node-'.$vars['node']->type.'-teaser';    
            $vars['template_files'][] = 'node-'.$vars['node']->nid.'-teaser';
        }
    }
}

function phptemplate_preprocess_block(&$vars)
{
    //the "cleaned-up" block title to be used for suggestion file name
    $subject = str_replace(" ", "-", strtolower($vars['block']->subject));

    $vars['template_files'] = array('block', 'block-'.$vars['block']->delta, 'block-'.$subject);    
}

In the template.php file I inserted the code below:
I found a tutorial online that gives the code, but I'm confused on how to get it to work.

I copied the code below and inserted it into the template.php from the theme HTML5_base.
I duplicated the page.tpl.php file and created custom pages -- page-gallery.tpl.php and page-articles.tpl.php. I inserted some text to the files just see that I've navigated to the pages w/ the changes. It looks like Drupal is not recognizing gallery.tpl.php and page-articles.tpl.php.

In the template.php there are the following functions:

html5_base_preprocess_page()

html5_base_preprocess_node()

html5_base_preprocess_block()

In the tutorial it uses these functions:

phptemplate_preprocess_page()

phptemplate_preprocess_block()

phptemplate_preprocess_node()

 function phptemplate_preprocess_page(&$vars)

{
    //code block from the Drupal handbook

    //the path module is required and must be activated
    if(module_exists('path'))
    {
        //gets the "clean" URL of the current page
        $alias = drupal_get_path_alias($_GET['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;
    }
}

function phptemplate_preprocess_node(&$vars)
{
    //default template suggestions for all nodes
    $vars['template_files'] = array();
    $vars['template_files'][] = 'node';

    //individual node being displayed
    if($vars['page'])
    {    
        $vars['template_files'][] = 'node-page';
        $vars['template_files'][] = 'node-'.$vars['node']->type.'-page';
        $vars['template_files'][] = 'node-'.$vars['node']->nid.'-page';
    }
    //multiple nodes being displayed on one page in either teaser
    //or full view
    else
    {
        //template suggestions for nodes in general
        $vars['template_files'][] = 'node-'.$vars['node']->type;
        $vars['template_files'][] = 'node-'.$vars['node']->nid;

        //template suggestions for nodes in teaser view
        //more granular control
        if($vars['teaser'])
        {
            $vars['template_files'][] = 'node-'.$vars['node']->type.'-teaser';    
            $vars['template_files'][] = 'node-'.$vars['node']->nid.'-teaser';
        }
    }
}

function phptemplate_preprocess_block(&$vars)
{
    //the "cleaned-up" block title to be used for suggestion file name
    $subject = str_replace(" ", "-", strtolower($vars['block']->subject));

    $vars['template_files'] = array('block', 'block-'.$vars['block']->delta, 'block-'.$subject);    
}

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

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

发布评论

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

评论(1

泪冰清 2024-10-15 19:43:38

啊!这样做很痛苦。

为什么不尝试一下 Ctools面板 模块。

Ctools 有很多有用的模块,您可以充分利用的模块称为“页面管理器”。它将允许您创建您选择的自定义页面,并使用面板模块应用自定义布局。

希望这可以简化事情。

Ah! That's a lot of pain to do this.

Why don't you try the Ctools and Panels modules.

Ctools has a lot of useful modules, the one you'd make good use of is called "Page Manager". It will allow you to create custom pages of your choice, and apply custom layouts using the Panels module.

Hope this simplifys things.

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