Вы здесь

Друпал 7: page.tpl.php

page.tpl.php — шаблон формирующий страницу.

Переменные

Системные переменные

  • $base_path — папка сайта
  • $directory: The directory the template is located in, e.g. modules/system or themes/bartik
  • $is_front — возвращает значение 1 (TRUE, если загружена первая страница сайта) или 0 (FALSE, если загружена любая другая страница)
  • $logged_in — переменная возвращает значение 1 (TRUE, если пользователь находится в аккаунте) или 0 (FALSE, если пользователь не находится в аккаунте)
  • $is_admin — переменная возвращает значение 1 (TRUE, если у пользователя есть право доступа к страницам управления сайтом) или 0 (FALSE, если у пользователя нет права доступа к страницам управления сайтом)

Переменные идентификации

  • $front_page — URL первой страницы сайта. Используется вместо переменной $base_path в случае ссылки на первую страницу сайта (переменная включает язык домена или префикс используемого языка)
  • $logo — адрес логотипа. Данные берутся со страницы темы, если в настройках показ логотипа запрещён, то показываться он не будет и при наличии этой переменной
  • $site_name — название сайта (информация берётся на странице информации о сайте). Если на странице темы показ названия сайта отключен, то выводится не будет
  • $site_slogan — слоган сайта (информация берётся на странице информации о сайте). Если в настройках темы показ слогана отключен, то выводится не будет

Переменные навигации

  • $main_menu (array) — массив основных ссылок
  • $secondary_menu (array) — массив дополнительных ссылок
  • $breadcrumb — цепочка навигации

Переменные содержания

  • $title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template
  • $title — заголовок страницы
  • $title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template
  • $messages — системные сообщения о статусе и ошибках (например документ такой-то обновлён, тег такой-то добавлен, запуск cron выполнен успешно и т.д. Для этой переменной следует использовать заметное оформление)
  • $tabs (array) — вкладки (например вкладки Просмотр, Правка и т.д.)
  • $action_links (array): Actions local to the page, such as 'Add menu' on the menu administration interface
  • $feed_icons: A string of all feed icons for the current page
  • $node: The node object, if there is an automatically-loaded node associated with the page, and the node ID is the second argument in the page's path (e.g. node/12345 and node/12345/revisions, but not comment/reply/12345)

Переменные регионов

  • $page['help']: Dynamic help text, mostly for admin pages
  • $page['highlighted']: Items for the highlighted content region
  • $page['content']: The main content of the current page
  • $page['sidebar_first']: Items for the first sidebar
  • $page['sidebar_second']: Items for the second sidebar
  • $page['header']: Items for the header region
  • $page['footer']: Items for the footer region

Пример шаблона

  <div id="page-wrapper"><div id="page">

    <div id="header"><div class="section clearfix">

      <?php if ($logo): ?>
        <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo">
          <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
        </a>
      <?php endif; ?>

      <?php if ($site_name || $site_slogan): ?>
        <div id="name-and-slogan">
          <?php if ($site_name): ?>
            <?php if ($title): ?>
              <div id="site-name"><strong>
                <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a>
              </strong></div>
            <?php else: /* Use h1 when the content title is empty */ ?>
              <h1 id="site-name">
                <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a>
              </h1>
            <?php endif; ?>
          <?php endif; ?>

          <?php if ($site_slogan): ?>
            <div id="site-slogan"><?php print $site_slogan; ?></div>
          <?php endif; ?>
        </div> <!-- /#name-and-slogan -->
      <?php endif; ?>

      <?php print render($page['header']); ?>

    </div></div> <!-- /.section, /#header -->

    <?php if ($main_menu || $secondary_menu): ?>
      <div id="navigation"><div class="section">
        <?php print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'inline', 'clearfix')), 'heading' => t('Main menu'))); ?>
        <?php print theme('links__system_secondary_menu', array('links' => $secondary_menu, 'attributes' => array('id' => 'secondary-menu', 'class' => array('links', 'inline', 'clearfix')), 'heading' => t('Secondary menu'))); ?>
      </div></div> <!-- /.section, /#navigation -->
    <?php endif; ?>

    <?php if ($breadcrumb): ?>
      <div id="breadcrumb"><?php print $breadcrumb; ?></div>
    <?php endif; ?>

    <?php print $messages; ?>

    <div id="main-wrapper"><div id="main" class="clearfix">

      <div id="content" class="column"><div class="section">
        <?php if ($page['highlighted']): ?><div id="highlighted"><?php print render($page['highlighted']); ?></div><?php endif; ?>
        <a id="main-content"></a>
        <?php print render($title_prefix); ?>
        <?php if ($title): ?><h1 class="title" id="page-title"><?php print $title; ?></h1><?php endif; ?>
        <?php print render($title_suffix); ?>
        <?php if ($tabs): ?><div class="tabs"><?php print render($tabs); ?></div><?php endif; ?>
        <?php print render($page['help']); ?>
        <?php if ($action_links): ?><ul class="action-links"><?php print render($action_links); ?></ul><?php endif; ?>
        <?php print render($page['content']); ?>
        <?php print $feed_icons; ?>
      </div></div> <!-- /.section, /#content -->

      <?php if ($page['sidebar_first']): ?>
        <div id="sidebar-first" class="column sidebar"><div class="section">
          <?php print render($page['sidebar_first']); ?>
        </div></div> <!-- /.section, /#sidebar-first -->
      <?php endif; ?>

      <?php if ($page['sidebar_second']): ?>
        <div id="sidebar-second" class="column sidebar"><div class="section">
          <?php print render($page['sidebar_second']); ?>
        </div></div> <!-- /.section, /#sidebar-second -->
      <?php endif; ?>

    </div></div> <!-- /#main, /#main-wrapper -->

    <div id="footer"><div class="section">
      <?php print render($page['footer']); ?>
    </div></div> <!-- /.section, /#footer -->

  </div></div> <!-- /#page, /#page-wrapper -->