drupal 使用 include 分隔模板代码页眉和页脚 [英] drupal separating template code header and footer with include

查看:20
本文介绍了drupal 使用 include 分隔模板代码页眉和页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 drupal 模板并尝试使用它

I'm creating a drupal template and tried using this

    <?php require "".base_path() . path_to_theme()."'/header.php'" ?>

它确实提供了正确的路径,但它提供了这个

and it does provide the right path, but it gave this

警告:require(/learn/learn_drupal/sites/all/themes/test_theme'/header.php'):无法打开流:require() 中没有这样的文件或目录(/Users/Devric/的第 33 行)Sites/learn/learn_drupal/sites/all/themes/test_theme/templates/html.tpl.php).

Warning: require(/learn/learn_drupal/sites/all/themes/test_theme'/header.php'): failed to open stream: No such file or directory in require() (line 33 of /Users/Devric/Sites/learn/learn_drupal/sites/all/themes/test_theme/templates/html.tpl.php).

有人知道如何分离代码吗?

anyone know how to separate the code?

推荐答案

如果我是你,我会阅读如何设置合适的 Drupal 主题.

If I were you I'd read up on how to set a proper Drupal theme.

首先在您的主题目录中构建一个模板文件夹.然后从根 modules/system/page.tpl.phpmodules/system/html.tpl.php 复制到这个新的模板文件夹.

Start by building a templates folder in your theme directory. Then copy over from the root modules/system/page.tpl.php and modules/system/html.tpl.php to this new templates folder.

这是您的主要主题文件.html.tpl.php 包含标题中的所有内容(元标记等)以及开始和结束正文标记.

This is your main theme files. html.tpl.php contains everything in your header (meta tags etc) and your start and end body tags.

page.tpl.php 是正文之间的内容,或者基本上是打印的内容 <?php print $page;?>.

page.tpl.php is what goes in between the body, or basically what is printed where it says <?php print $page; ?>.

如果您打开 page.tpl.php 文件,您将看到您的所有区域等.这是您的页面轮廓.使用它来整理使用硬代码或 Drupal 出色的块系统的任何页脚、页眉等.

If you open the page.tpl.php file you'll see all your regions etc. This is your page outline. Use this as to sort out any footers, headers etc using either hard code or Drupal's excellent block system.

如果您认为您的页面是这样应该会有所帮助:

If you think of your page like this is should help:

html.tpl.php -> opens your html page
   - page.tpl.php -> any constant elements above the content
      - node.tpl.php -> the content
   - page.tpl.php -> any constant elements below the content
html.tpl.php -> closes your html page

您不需要设置自己的包含,因为 Drupal 已经为您完成了所有这些工作.这是一个陡峭的学习曲线,我真的很难开始,但没有必要不以 Drupal 的方式做事,因为你正在失去使它成为如此优秀的 CMS 的原因.

You don't need to set up your own includes because Drupal already does all this for you. It's a steep learning curve and I really struggled to start off with but there's no point not doing things the Drupal way as you're losing what makes it such a good CMS.

您可以在此处阅读更多信息 - http://drupal.org/documentation/theme

You can read more here - http://drupal.org/documentation/theme

您可以将块设置为特定于页面,然后为它们设置主题.例如,设置一个名为 about header 的块,并设置为仅显示在块管理页面中您希望它出现的页面上.您可以按照与节点相同的方式为每个块设置模板.

You can set up blocks to be page specific and then theme them. Set up a block called about header for example and set to only be displayed on the pages you want it on in the blocks admin page. You can set templates up for each block in the same way you do nodes.

这篇关于drupal 使用 include 分隔模板代码页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆