使用Drupal 7中的front.tpl进行另一个页面

Jam*_*ngs 2 templates drupal frontpage

非常直截了当的问题:

我在drupal 7站点中使用了page-front.tpl和page.tpl模板页面.但是,我想在另一页上使用page-front.tpl.这是可能的还是我需要创建另一个.tpl页面来执行此操作.

我正在处理的网站分为两个部分,它基本上是两个单独的网站,您可以在您的消费者或企业主之间进行切换.所以我想使用front.tpl模板作为每个站点的主页.

干杯.

Vla*_*lat 6

您可以theme_preprocess_page在主题template.php文件中添加功能,然后在模板建议列表中添加模板名称.

function mytheme_preprocess_page(&$vars) {
    // you can perform different if statements
    // if () {...
        $template = 'page__front'; // you should replace dash sign with underscore
        $vars['theme_hook_suggestions'][] = $template;
    // }
}
Run Code Online (Sandbox Code Playgroud)

编辑

如果要按路径别名指定模板名称,可以编写如下代码:

function phptemplate_preprocess_page(&$variables) {
    if (module_exists('path')) {
        $alias = drupal_get_path_alias($_GET['q']);
        if ($alias != $_GET['q']) {
            $template = 'page_';
            foreach (explode('/', $alias) as $part) {
                $template.= "_{$part}";
                $variables['theme_hook_suggestions'][] = $template;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果没有此功能,默认情况下您将拥有以下节点模板建议:

array(
    [0] => page__node
    [1] => page__node__%
    [2] => page__node__1
)
Run Code Online (Sandbox Code Playgroud)

并且此函数将向您的节点应用以下新模板建议.带node/1路径和page/about别名的示例节点:

array(
    [0] => page__node
    [1] => page__node__%
    [2] => page__node__1
    [3] => page__page
    [4] => page__page_about
)
Run Code Online (Sandbox Code Playgroud)

之后,您可以使用page--page-about.tpl.php您的页面.

如果你想申请page--front.tpl.php你的说法node/15,那么在这个函数中你可以添加if语句.

function phptemplate_preprocess_page(&$variables) {
    if (module_exists('path')) {
        $alias = drupal_get_path_alias($_GET['q']);
        if ($alias != $_GET['q']) {
            $template = 'page_';
            foreach (explode('/', $alias) as $part) {
                $template.= "_{$part}";
                $variables['theme_hook_suggestions'][] = $template;
            }
        }
    }

    if ($_GET['q'] == 'node/15') {
        $variables['theme_hook_suggestions'][] = 'page__front';
    }
}
Run Code Online (Sandbox Code Playgroud)

这将为您提供以下模板建议:

array(
    [0] => page__node
    [1] => page__node__%
    [2] => page__node__1
    [3] => page__page
    [4] => page__page_about
    [5] => page__front
)
Run Code Online (Sandbox Code Playgroud)

最高索引 - 最高模板优先级.