<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 431,  comments - 344,  trackbacks - 0

    As of Drupal 4.7, themes can implement any number of regions for rendering blocks and other content into. If you take a look at the 'blocks' administration page in Drupal, you will see that regions are essentially containers to which you can add those blocks. You can also add other non-block content to a region using PHP. An example of a region is your sidebar.

    These regions can be assigned to either the whole page or any other themed elements, including in nodes or comments.

    The PHPTemplate engine defines five default regions: left, right, content, header, and footer. To implement these regions, themes need only include $sidebar_left, $sidebar_right, $content, $header, and $footer_message variables in their page.tpl.php files, e.g., <?php print $header; ?>.

    How to define custom regions

    If you want to have your own set of regions for a theme, you do this by defining a _regions() hook. In this case, your custom regions will override those defined by default in PHPTemplate.

    If the theme doesn't have a template.php file in its directory, create one; otherwise use the existing template.php file. In either case, add a mytheme_regions() function to define your regions. Each region needs to have a name (a string with no spaces) and a description (the text that will show up in, for example, the block configuration pages). The following would define all the standard PHPTemplate regions except the left sidebar and, in addition, two new regions for a theme called "mytheme".

    <?php
    function mytheme_regions() {
      return array(
       
    'right' => t('right sidebar'),
       
    'content' => t('content'),
       
    'header' => t('header'),
       
    'footer' => t('footer'),
       
    'floater' => t('floater'),
       
    'inline1' => t('inline 1')
      );
    }
    ?>

     

    Note: Regarding the name of the function:

    • use the name of your theme instead of mytheme_regions(), eg: bluemarine_regions()
    • Don't use a hyphen in the name of a region; an underscore is OK.
    • Also, your theme name is your base theme name not the name of your style.css directory (if you are using one). For example, box_cleanslate overrides the style.css file of the box_grey theme; therefore you should name your function box_grey_regions.

    How to write the theme's region variables to the page.

    If you're assigning your region to page.tpl.php, you don't need to worry about creating a variable for your region and assigning content to it; PHPTemplate handles this automatically. All you need to do is write the variables to the page, by editing your theme's page.tpl.php file. For each new region you've defined, include in page.tpl.php a print call. For the 'floater' region defined above, this would look like:

    <?php  print $floater;?>.

    Of course, you'll probably want to use HTML, CSS, and possibly PHP (e.g., if tests) to get your new regions looking how you want them.

    Inline regions: how to assign regions to nodes, comments, etc.

    By default, all defined regions are passed to page.tpl.php. But with an extra step you can also choose to make specific regions available to any other template file: node.tpl.php, comment.tpl.php, etc. Here's how.

    In the same template.php file as you defined the regions in, define a function _phptemplate_variables() (or use an existing one if there's one already defined). What you'll do here is assign region content to a specific theme call. When _phptemplate_variables() is called, it receives the theme argument as the $hook variable, for instance 'node'. So we can assign new regions to the node template like this:

    <?php
    function _phptemplate_variables($hook, $variables) {
     
    // Load the node region only if we're not in a teaser view.
     
    if ($hook == 'node' && !$vars['teaser']) {
       
    // Load region content assigned via blocks.
       
    foreach (array('inline1') as $region) {
         
    $variables[$region] = theme('blocks', $region);
        }
      }
      return
    $variables;
    }
    ?>

     

    Note that we're testing to make sure we aren't in a 'teaser' view, so that the region will be loaded only in a full node view.

    Now, in your node template, you can include the region variable in your output. Here's the standard phptemplate node.tpl.php with an 'inline1' region added:

      <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
        <?php if ($picture) {
          print
    $picture;
        }
    ?>

        <?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>
        <span class="submitted"><?php print $submitted?></span>
        <span class="taxonomy"><?php print $terms?></span>
        <div class="content"><div class="floatleft"><?php print $inline1?></div><?php print $content?></div>
        <?php if ($links) { ?><div class="links">&raquo; <?php print $links?></div><?php }; ?>
      </div>

     

    Likely you'll want to add style declarations to the region, which you do as usual via the theme's style.css file. Here, for example, we could make the inline region float left:

    div.floatleft {
      float: left;
    }

     

    Because a node's variables are passed to other node templates, you can also do your customized display in node-type templates.

    And this same basic approach can be applied to any other themed area. This example assigns specific regions to nodes and comments:

    <?php
    function _phptemplate_variables($hook, $variables) {
     
    // Load region content assigned via blocks.
      // Load the node region only if we're not in a teaser view.
     
    if ($hook == 'node' && !$variables['teaser']) {
        foreach (array(
    'node1', 'node2') as $region) {
         
    $variables[$region] = theme('blocks', $region);
        }
      }
      else if (
    $hook == 'commment') {
        foreach (array(
    'comment1', 'comment2') as $region) {
         
    $variables[$region] = theme('blocks', $region);
        }
      }
      return
    $variables;
    }
    ?>

     

    Regions without blocks

    If you want to assign content to regions but not have it output via blocks, do so with the drupal_set_content() function. This allows you to bypass the regular block system. Try something like this:

    Set content to regions
    In your module code, set content to the regions. You can use region names that aren't listed in your themename_regions() array. That way, the regions won't be available for blocks, and so won't end up with block content in them. Say your regions are called 'region1' and 'region2'. In your module code, do this:

    <?php
    $output
    = 'whatever';
    drupal_set_content('region1', $output);
    ?>

     

    In a template.php file, set a variable and assign the region content to it.

    <?php
    function _phptemplate_variables($hook, $variables) {
     
    // Load region content assigned via drupal_set_content().
     
    if ($hook == 'page') {
        foreach (array(
    'region1', 'region2') as $region) {
         
    $variables[$region] = drupal_get_content($region);
        }
      }
      return
    $variables;
    }
    ?>

     

    Output your content
    In your page.tpl.php file, output the regions where you want them:

    <?php
    print $region1;
    ?>

     

    posted on 2007-11-06 11:49 周銳 閱讀(160) 評(píng)論(0)  編輯  收藏 所屬分類: PHP
    主站蜘蛛池模板: 中文字幕无线码免费人妻| 亚洲高清偷拍一区二区三区 | 两个人看的www高清免费观看| 亚洲日韩国产欧美一区二区三区 | 亚洲国产精品无码久久九九大片| 久久久久亚洲av无码尤物| 亚洲?V无码乱码国产精品| 日韩av无码成人无码免费| 最近2019中文字幕免费直播 | 亚洲日韩v无码中文字幕| 国产精品无码一区二区三区免费| 91在线视频免费91| 91福利视频免费| 久久青草免费91线频观看不卡| rh男男车车的车车免费网站| 国产成人综合久久精品亚洲| 亚洲乱码无人区卡1卡2卡3| 亚洲国产成+人+综合| 亚洲综合激情九月婷婷| 亚洲AV无码一区二区乱孑伦AS | 日韩精品免费一线在线观看| 亚洲AV日韩综合一区| 性色av极品无码专区亚洲 | 国产中文字幕免费| 天天操夜夜操免费视频| 99热在线精品免费全部my| 中文字幕乱码免费视频| 1000部啪啪未满十八勿入免费| 8x8×在线永久免费视频| 日本免费人成视频在线观看| 久久精品成人免费网站| 日本中文字幕免费高清视频| 无码人妻久久一区二区三区免费 | 国产免费啪嗒啪嗒视频看看| 国产一区在线观看免费| 国产一卡二卡≡卡四卡免费乱码| 内射无码专区久久亚洲| 亚洲爽爽一区二区三区| 亚洲性猛交XXXX| 亚洲天天在线日亚洲洲精| 精品日韩亚洲AV无码|